Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class EnemyShot : MonoBehaviour
{
public Rigidbody2D bullet;
public Transform gunPoint;
public float fireRate = 1;
float elapsedTime = 0.0f;
public float speed = 10;
public float ScatterBullets = 0;
public Collider2D col;
public AudioSource SoundShot;
public AudioClip Hit_00;
void OnTriggerStay2D(Collider2D col)
{
if (col.gameObject.tag == "Player")
{
elapsedTime += Time.deltaTime;
if (elapsedTime > fireRate)
{
elapsedTime = 0.0f;
Vector3 direction = gunPoint.position;
Rigidbody2D clone = Instantiate(bullet, gunPoint.position, gunPoint.rotation * Quaternion.Euler(Random.Range(-ScatterBullets, 0), Random.Range(-ScatterBullets, ScatterBullets), 0)) as Rigidbody2D;
clone.velocity = transform.TransformDirection (gunPoint.right * speed);
clone.transform.right = gunPoint.right;
SoundShot.PlayOneShot(Hit_00);
}
}
}
}
using System.Collections;
public class EnemyShot : MonoBehaviour
{
public Rigidbody2D bullet;
public Transform gunPoint;
public float fireRate = 1;
float elapsedTime = 0.0f;
public float speed = 10;
public float ScatterBullets = 0;
public Collider2D col;
public AudioSource SoundShot;
public AudioClip Hit_00;
void OnTriggerStay2D(Collider2D col)
{
if (col.gameObject.tag == "Player")
{
elapsedTime += Time.deltaTime;
if (elapsedTime > fireRate)
{
elapsedTime = 0.0f;
Vector3 direction = gunPoint.position;
Rigidbody2D clone = Instantiate(bullet, gunPoint.position, gunPoint.rotation * Quaternion.Euler(Random.Range(-ScatterBullets, 0), Random.Range(-ScatterBullets, ScatterBullets), 0)) as Rigidbody2D;
clone.velocity = transform.TransformDirection (gunPoint.right * speed);
clone.transform.right = gunPoint.right;
SoundShot.PlayOneShot(Hit_00);
}
}
}
}
Проблема в том, что пули летят по по прямой вне зависимости от значения переменной ScatterBullets, в чём причина? Объясните пожалуйста, буду благодарен)