Media is too big
VIEW IN TELEGRAM
اموزش ساخت باران در یونیتی
@UnityEngine
@UnityEngine
🔶 #یونیتی
رفتن به مرحله ی دلخواه با کلیک روی باتن
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Move : MonoBehaviour {
public Button btn1;
void Start () {
btn1.onClick.AddListener(TaskOnClick);
}
void TaskOnClick(){
SceneManager.LoadScene(" اسم مرحله دلخواه");
}
}
@UnityEngine
رفتن به مرحله ی دلخواه با کلیک روی باتن
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Move : MonoBehaviour {
public Button btn1;
void Start () {
btn1.onClick.AddListener(TaskOnClick);
}
void TaskOnClick(){
SceneManager.LoadScene(" اسم مرحله دلخواه");
}
}
@UnityEngine
آموزش پرداخت درون برنامه ای سایت ایران اپس
s6.picofile.com/file/8205313350/Untitled_13.mp4.html
قسمت 1☝️☝️☝️
s3.picofile.com/file/8205315000/Untitled_14.mp4.html
قسمت 2☝️
#یونیتی
@UnityEngine
s6.picofile.com/file/8205313350/Untitled_13.mp4.html
قسمت 1☝️☝️☝️
s3.picofile.com/file/8205315000/Untitled_14.mp4.html
قسمت 2☝️
#یونیتی
@UnityEngine
برای اینکه بتونیم از این کد ها استفاده کنیم ابتدا باید دوتا شی ایجاد کنیم . مثلا دو مکعب ایجاد می کنیم به نام Enemy و Player.
حالا یک فایل سی شارپ با نام EnemyAI ایجاد می کنیم ( توجه کنید که حتما اسمش این باشه ). کد زیر رو توش کپی می کنیم.
کد:
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxdistance;
private Transform myTransform;
void Awake(){
myTransform = transform;
}
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
maxdistance = 2;
}
void Update () {
Debug.DrawLine(target.position, myTransform.position, Color.red);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
if(Vector3.Distance(target.position, myTransform.position) > maxdistance){
//Move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}
فایل رو سیو می کنیم و به شی Enemy مرتبطش می کنیم و شی Player رو به عنوان هدف بهش معرفی کرده و مقادیر سرعت حرکت سرعت چرخش و میزان فاصلشو با شی مورد نظر مشخص می کنیم.
@UnityEngine
خب حالا یک فایل C# دیگه با نام PlayerHealth ساخته و کد زیر رو درش کپی می کنیم.
کد:
using UnityEngine;using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLength;
void Start () {
healthBarLength = Screen.width / 2;
}
void Update () {
AddjustCurrentHealth(0);
}
void OnGUI(){
GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj) {
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
}
حال فایل رو سیو می کنیم و به شی Player متصلش می کنیم و میزان سقف خون ، میزان خون حال حاضر و طول میزان خونی که در صفحه نمایش نمایش داده میشه که البته نیازی به تعیین این نیست و خودش اتوماتیک تعیین میشه.
خب حالا نوبت به حمله دشمن میرسه . یک فایل با نام EnemyAttack می سازیم و کد زیر رو درش کپی می کنیم.
کد:
using UnityEngine;using System.Collections;
public class EnemyAttack : MonoBehaviour {
public GameObject target;
public float attackTime;
public float coolDown;
void Start () {
attackTime = 0;
coolDown = 2.0f;
}
void Update () {
if(attackTime > 0)
attackTime -= Time.deltaTime;
if(attackTime < 0)
attackTime = 0;
if(attackTime == 0) {
Attack();
attackTime = coolDown;
}
}
private void Attack() {
float distance = Vector3.Distance(target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
if(distance < 2.5f) {
if(direction > 0) {
PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
eh.AddjustCurrentHealth(-10);
}
}
}
}
بعد از اینکار فایل رو ذخیره کرده و به شی دشمن نسبت میدیم و شی هدف که همون Player هست رو بهش معرفی کرده و مقدار زمان حمله و زمان آماده سازی رو براش تعیین می کنیم.
حالا بازی رو اجرا می کنیم و میبینیم که به دنبال پلیر میفته تا نگیردشم ول کن نیستش.
@UnityEngine
#یونیتی
حالا یک فایل سی شارپ با نام EnemyAI ایجاد می کنیم ( توجه کنید که حتما اسمش این باشه ). کد زیر رو توش کپی می کنیم.
کد:
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxdistance;
private Transform myTransform;
void Awake(){
myTransform = transform;
}
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
maxdistance = 2;
}
void Update () {
Debug.DrawLine(target.position, myTransform.position, Color.red);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
if(Vector3.Distance(target.position, myTransform.position) > maxdistance){
//Move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}
فایل رو سیو می کنیم و به شی Enemy مرتبطش می کنیم و شی Player رو به عنوان هدف بهش معرفی کرده و مقادیر سرعت حرکت سرعت چرخش و میزان فاصلشو با شی مورد نظر مشخص می کنیم.
@UnityEngine
خب حالا یک فایل C# دیگه با نام PlayerHealth ساخته و کد زیر رو درش کپی می کنیم.
کد:
using UnityEngine;using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLength;
void Start () {
healthBarLength = Screen.width / 2;
}
void Update () {
AddjustCurrentHealth(0);
}
void OnGUI(){
GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj) {
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
}
حال فایل رو سیو می کنیم و به شی Player متصلش می کنیم و میزان سقف خون ، میزان خون حال حاضر و طول میزان خونی که در صفحه نمایش نمایش داده میشه که البته نیازی به تعیین این نیست و خودش اتوماتیک تعیین میشه.
خب حالا نوبت به حمله دشمن میرسه . یک فایل با نام EnemyAttack می سازیم و کد زیر رو درش کپی می کنیم.
کد:
using UnityEngine;using System.Collections;
public class EnemyAttack : MonoBehaviour {
public GameObject target;
public float attackTime;
public float coolDown;
void Start () {
attackTime = 0;
coolDown = 2.0f;
}
void Update () {
if(attackTime > 0)
attackTime -= Time.deltaTime;
if(attackTime < 0)
attackTime = 0;
if(attackTime == 0) {
Attack();
attackTime = coolDown;
}
}
private void Attack() {
float distance = Vector3.Distance(target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
if(distance < 2.5f) {
if(direction > 0) {
PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
eh.AddjustCurrentHealth(-10);
}
}
}
}
بعد از اینکار فایل رو ذخیره کرده و به شی دشمن نسبت میدیم و شی هدف که همون Player هست رو بهش معرفی کرده و مقدار زمان حمله و زمان آماده سازی رو براش تعیین می کنیم.
حالا بازی رو اجرا می کنیم و میبینیم که به دنبال پلیر میفته تا نگیردشم ول کن نیستش.
@UnityEngine
#یونیتی
👍1
دانلود آخرین نسخه یونیتی
نسخه 2018.1.6f1
https://dl2.soft98.ir/adobe/Unity.3D.Pro.2018.1.6f1.x64.rar?1530939383
____________________________
دانلود addons
http://dl.downloadly.ir/Files/Software2/Unity_Pro_2018.1.6f1_addons_Downloadly.ir.rar
دوستان فعلا هیچگونه مادلی در سایت های ایرانی پیدا نشد
میتوانید وقتی یونیتی رو کرک کردید برید از خود سایت یونیتی با فیلتر شکن مادل مورد نظرتون رو دانلود کنید
#یونیتی
@UnityEngine
نسخه 2018.1.6f1
https://dl2.soft98.ir/adobe/Unity.3D.Pro.2018.1.6f1.x64.rar?1530939383
____________________________
دانلود addons
http://dl.downloadly.ir/Files/Software2/Unity_Pro_2018.1.6f1_addons_Downloadly.ir.rar
دوستان فعلا هیچگونه مادلی در سایت های ایرانی پیدا نشد
میتوانید وقتی یونیتی رو کرک کردید برید از خود سایت یونیتی با فیلتر شکن مادل مورد نظرتون رو دانلود کنید
#یونیتی
@UnityEngine