Start Unity
374 subscribers
7 photos
1 video
11 links
هیچ پروسه ای سخت نیست به شرطی که شروعش کنی..

🎮 #یونیتی
👨‍💻 #برنامه_نویسی
📚 #آموزش
🧩 #آزمون

گروه: @StartUnityGP

🫂 @AmirHDeveloper @HaminGames
Download Telegram
Channel created
.
👌5🔥4👍2🙏2
Start Unity
#نکات_مهم
از اینا 4 تا دونشو عادت دارم خودم🤦‍♂️😂😂
Channel photo updated
برخی از متدهای کلاس‌های Vector2 و Vector3 همراه با نمونه کد:

### Vector2:

1. `Distance(Vector2 a, Vector2 b)`:
- توضیح: این متد فاصله‌ی اقلیدسی (Euclidean distance) بین دو نقطه‌ی مشخص را محاسبه می‌کند.
- نمونه کد:

     Vector2 pointA = new Vector2(1.0f, 2.0f);
Vector2 pointB = new Vector2(4.0f, 6.0f);

float distance = Vector2.Distance(pointA, pointB);


2. `Dot(Vector2 lhs, Vector2 rhs)`:
- توضیح: این متد محصول نقطه‌ای (dot product) دو بردار را محاسبه می‌کند.
- نمونه کد:

     Vector2 vectorA = new Vector2(2.0f, 3.0f);
Vector2 vectorB = new Vector2(1.0f, 2.0f);

float dotProduct = Vector2.Dot(vectorA, vectorB);


### Vector3:

1. `Angle(Vector3 from, Vector3 to)`:
- توضیح: این متد زاویه‌ی بین دو بردار را با استفاده از محصول نقطه‌ای محاسبه می‌کند.
- نمونه کد:

     Vector3 fromVector = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 toVector = new Vector3(0.0f, 1.0f, 0.0f);

float angle = Vector3.Angle(fromVector, toVector);


2. `Reflect(Vector3 inDirection, Vector3 inNormal)`:
- توضیح: این متد بازتاب بردار وارون شده از یک سطح را محاسبه می‌کند.
- نمونه کد:

     Vector3 incident = new Vector3(1.0f, -1.0f, 0.0f).normalized;
Vector3 normal = new Vector3(0.0f, 1.0f, 0.0f).normalized;

Vector3 reflected = Vector3.Reflect(incident, normal);


3. `Project(Vector3 vector, Vector3 onNormal)`:
- توضیح: این متد پروژکشن یک بردار بر روی یک بردار دیگر را محاسبه می‌کند.
- نمونه کد:

     Vector3 vectorToProject = new Vector3(3.0f, 4.0f, 5.0f);
Vector3 ontoVector = new Vector3(1.0f, 0.0f, 0.0f);

Vector3 projectedVector = Vector3.Project(vectorToProject, ontoVector);


4. `Lerp(Vector3 a, Vector3 b, float t)`:
- توضیح: این متد یک بردار در طول یک مسیر خطی بین دو بردار مبدأ و مقصد ایجاد می‌کند.
- نمونه کد:

     Vector3 vectorA = new Vector3(1.0f, 2.0f, 3.0f);
Vector3 vectorB = new Vector3(4.0f, 5.0f, 6.0f);

Vector3 lerpedVector = Vector3.Lerp(vectorA, vectorB, 0.5f);


5. `Slerp(Vector3 a, Vector3 b, float t

)`:

- توضیح: این متد یک بردار در طول یک مسیر قطبی بین دو بردار مبدأ و مقصد ایجاد می‌کند.
- نمونه کد:

     Vector3 vectorA = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 vectorB = new Vector3(0.0f, 1.0f, 0.0f);

Vector3 slerpedVector = Vector3.Slerp(vectorA, vectorB, 0.5f);


6. `RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta)`:
- توضیح: این متد یک بردار را به سمت یک بردار هدف چرخانده و محدودیت‌هایی برای حرکت را اعمال می‌کند.
- نمونه کد:

     Vector3 currentVector = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 targetVector = new Vector3(0.0f, 1.0f, 0.0f);

float maxRadiansDelta = 0.1f;
float maxMagnitudeDelta = 0.01f;

Vector3 rotatedVector = Vector3.RotateTowards(currentVector, targetVector, maxRadiansDelta, maxMagnitudeDelta);


7. `MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta)`:
- توضیح: این متد یک بردار را به سمت یک بردار هدف حرکت می‌دهد با محدودیت فاصله حداکثری.
- نمونه کد:

     Vector3 currentVector = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 targetVector = new Vector3(0.0f, 1.0f, 0.0f);

float maxDistanceDelta = 0.1f;

Vector3 movedVector = Vector3.MoveTowards(currentVector, targetVector, maxDistanceDelta);


8. `SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed)`:
- توضیح: این متد یک بردار را به سمت یک بردار هدف با استفاده از حرکت انسیابی (Smooth Damping) حرکت می‌دهد.
- نمونه کد:

     Vector3 currentVector = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 targetVector = new Vector3(0.0f, 1.0f, 0.0f);
Vector3 currentVelocity = Vector3.zero;
float smoothTime = 0.5f;
float maxSpeed = 2.0f;

Vector3 smoothedVector = Vector3.SmoothDamp(currentVector, targetVector, ref currentVelocity, smoothTime, maxSpeed);


#یونیتی #برنامه_نویسی
🔥5
در Unity، کلاس Mathf حاوی متدها و توابع ریاضی مختلفی است که برای انجام عملیات ریاضی مورد نیاز در بازی‌ها و شبیه‌سازی‌های سه‌بعدی استفاده می‌شوند. در زیر توضیحات برخی از متدهای این کلاس به همراه نمونه کد آمده است:

1. `Abs(float value)`:
- توضیح: بازگرداندن مقدار مطلق یک عدد.
- نمونه کد:

     float absoluteValue = Mathf.Abs(-5.0f);


2. `Sin(float f)`, `Cos(float f)`, `Tan(float f)`:
- توضیح: محاسبه سینوس، کسینوس و تانژانت یک زاویه به رادیان.
- نمونه کد:

     float angleInRadians = Mathf.PI / 4.0f; // 45 degrees in radians

float sineValue = Mathf.Sin(angleInRadians);
float cosineValue = Mathf.Cos(angleInRadians);
float tangentValue = Mathf.Tan(angleInRadians);


3. `Sqrt(float f)`:
- توضیح: محاسبه ریشه مربعی یک عدد.
- نمونه کد:

     float squareRootValue = Mathf.Sqrt(25.0f); // 5.0


4. `Pow(float f, float p)`:
- توضیح: محاسبه توان یک عدد به توان دیگر.
- نمونه کد:

     float result = Mathf.Pow(2.0f, 3.0f); // 8.0


5. `Round(float f)`:
- توضیح: گرد کردن یک عدد به نزدیکترین عدد صحیح.
- نمونه کد:

     float roundedValue = Mathf.Round(3.7f); // 4.0


6. `Ceil(float f)`, `Floor(float f)`:
- توضیح: گرد کردن به سمت بالا و پایین به نزدیکترین عدد صحیح.
- نمونه کد:

     float ceilValue = Mathf.Ceil(3.2f); // 4.0
float floorValue = Mathf.Floor(3.8f); // 3.0


7. `Min(float a, float b)`, `Max(float a, float b)`:
- توضیح: بازگرداندن کمترین یا بزرگترین عدد از دو عدد داده شده.
- نمونه کد:

     float minValue = Mathf.Min(5.0f, 7.0f); // 5.0
float maxValue = Mathf.Max(3.0f, 9.0f); // 9.0


8. `Clamp(float value, float min, float max)`:
- توضیح: محدود کردن یک عدد بین یک حداقل و حداکثر مشخص.
- نمونه کد:

     float clampedValue = Mathf.Clamp(3.0f, 1.0f, 5.0f); // 3.0


9. `Lerp(float a, float b, float t)`:
- توضیح: ایجاد یک عدد در طول یک مسیر خطی بین دو عدد مبدأ و مقصد.
- نمونه کد:

     float lerpedValue = Mathf.Lerp(1.0f, 3.0f, 0.5f); // 2.0


10. `InverseLerp(float a, float b, float value)`:
- توضیح: محاسبه مقدار پارامتر t که عدد value بین a و b قرار دارد.
- نمونه کد:

     float inverseLerpValue = Mathf.InverseLerp(1.0f, 5.0f, 3.0f); // 0.5


11. `MoveTowards(float current, float target, float maxDelta)`:
- توضیح: حرکت یک عدد به سمت یک عدد هدف با محدودیت فاصله حداکثری.
- نمونه کد:

     float current = 2.0f;
float target = 5.0f;
float maxDelta = 1.0f;

float movedValue = Mathf.MoveTowards(current, target, maxDelta); // 3.0


12. `SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed)`:
- توضیح: انجام حرکت انسیابی (Smooth Damping) عدد به سمت یک عدد هدف.
- نمونه کد:

     float current = 2.0f;
float target = 5.0f;
float currentVelocity = 0.0f;
float smoothTime = 0.5f;
float maxSpeed = 2.0f;

float smoothedValue = Mathf.SmoothDamp(current, target, ref currentVelocity, smoothTime, max

Speed);


#یونیتی #برنامه_نویسی
🔥5👍2
در Unity، کلاس Quaternion برای نمایش و عملیات مربوط به چرخش‌ها و جهت‌ها در سه بعد استفاده می‌شود. در زیر توضیحات برخی از متدهای این کلاس به همراه نمونه کد آمده است:

1. `Quaternion.Euler(float x, float y, float z)`:
- توضیح: ایجاد یک Quaternion بر اساس زوایای Euler (Pitch، Yaw، Roll).
- نمونه کد:

     Quaternion rotation = Quaternion.Euler(45.0f, 90.0f, 0.0f);


2. `Quaternion.AngleAxis(float angle, Vector3 axis)`:
- توضیح: ایجاد یک Quaternion بر اساس یک زاویه و محور چرخش.
- نمونه کد:

     float angle = 30.0f;
Vector3 axis = new Vector3(0.0f, 1.0f, 0.0f);

Quaternion rotation = Quaternion.AngleAxis(angle, axis);


3. `Quaternion.identity`:
- توضیح: Quaternion هویت (بدون چرخش یا جهت).
- نمونه کد:

     Quaternion identityQuaternion = Quaternion.identity;


4. `Quaternion.LookRotation(Vector3 forward, Vector3 upwards)`:
- توضیح: ایجاد یک Quaternion که به سمت یک جهت مشخص نگاه می‌کند.
- نمونه کد:

     Vector3 forwardDirection = new Vector3(0.0f, 0.0f, 1.0f);
Vector3 upDirection = Vector3.up;

Quaternion rotation = Quaternion.LookRotation(forwardDirection, upDirection);


5. `Quaternion.Slerp(Quaternion a, Quaternion b, float t)`:
- توضیح: ایجاد یک Quaternion در طول یک مسیر قطبی بین دو Quaternion مبدأ و مقصد.
- نمونه کد:

     Quaternion quaternionA = Quaternion.Euler(0.0f, 90.0f, 0.0f);
Quaternion quaternionB = Quaternion.Euler(0.0f, 180.0f, 0.0f);

float t = 0.5f;
Quaternion slerpedQuaternion = Quaternion.Slerp(quaternionA, quaternionB, t);


6. `Quaternion.Lerp(Quaternion a, Quaternion b, float t)`:
- توضیح: ایجاد یک Quaternion در طول یک مسیر خطی بین دو Quaternion مبدأ و مقصد.
- نمونه کد:

     Quaternion quaternionA = Quaternion.Euler(0.0f, 90.0f, 0.0f);
Quaternion quaternionB = Quaternion.Euler(0.0f, 180.0f, 0.0f);

float t = 0.5f;
Quaternion lerpedQuaternion = Quaternion.Lerp(quaternionA, quaternionB, t);


7. `Quaternion.identity`:
- توضیح: Quaternion هویت (بدون چرخش یا جهت).
- نمونه کد:

     Quaternion identityQuaternion = Quaternion.identity;


8. `Quaternion.Inverse(Quaternion rotation)`:
- توضیح: معکوس یک Quaternion.
- نمونه کد:

     Quaternion originalRotation = Quaternion.Euler(30.0f, 45.0f, 60.0f);
Quaternion inverseRotation = Quaternion.Inverse(originalRotation);


9. `Quaternion.Euler(float x, float y, float z)`:
- توضیح: ایجاد یک Quaternion بر اساس زوایای Euler (Pitch، Yaw، Roll).
- نمونه کد:

     Quaternion rotation = Quaternion.Euler(45.0f, 90.0f, 0.0f);


10. `Quaternion.RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta)`:
- توضیح: چرخش یک Quaternion به سمت یک Quaternion هدف با محدودیت زاویه.
- نمونه کد:

      Quaternion fromRotation = Quaternion.Euler(0.0f, 90.0f, 0.0f);
Quaternion toRotation = Quaternion.Euler(0.0f, 180.0f

, 0.0f);
float maxDegreesDelta = 30.0f;

Quaternion rotatedQuaternion = Quaternion.RotateTowards(fromRotation, toRotation, maxDegreesDelta);


11. `Quaternion.Euler(Vector3 euler)`:
- توضیح: ایجاد یک Quaternion بر اساس زوایای Euler (Pitch، Yaw، Roll) در یک Vector3.
- نمونه کد:

     Vector3 eulerAngles = new Vector3(45.0f, 90.0f, 0.0f);
Quaternion rotation = Quaternion.Euler(eulerAngles);


این متدها تنها یک بخش کوچک از توابع Quaternion در Unity هستند و برای کاربردهای مختلف می‌توانید به مستندات Unity مراجعه کنید.

#یونیتی #برنامه_نویسی
🔥31👍1