If I use Random.Range for accuracy bullets fly same direction.
Changing Range I change accuracy. If I turn off Random.Range Bulletscript works correctly
but bullets fly straight line wich is not looking realistic. How can I use Random.Range to change accuracy
level?
This is my Bulletscript
using UnityEngine;
using System.Collections;
public class Bullet : MonoBehaviour {
private float BulletSpeed = 50f;
public GameObject Bulletprefab;
private Transform myTransform;
private float x, y, z;
void Start ()
{
}
void Update ()
{
float BulletMove = BulletSpeed * Time.deltaTime;
transform.Translate(Vector3.forward * BulletMove);
//If I exclude Random.Range function script works correctly
x = Random.Range(-3f, 3f); // I need Bullets fly within (-3, 3) Range. //That's for accuracy
y = Random.Range(-3f, 3f); // same
z = Random.Range(-3f, 3f); // same
transform.eulerAngles = new Vector3(x, y, z);
Destroy(gameObject, 2f);
}
}
Player script
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
private float PlayerSpeed = 20;
private float rotationSpeed = 60;
public GameObject BulletPrefab;
void Update()
{
float PlayerMove = Input.GetAxisRaw("Vertical") * PlayerSpeed * Time.deltaTime;
transform.Translate(Vector3.forward * PlayerMove);
float PlayerRotation = Input.GetAxisRaw("Horizontal") * rotationSpeed * Time.deltaTime;
transform.Rotate(Vector3.up * PlayerRotation);
if(Input.GetKey(KeyCode.Mouse0))
{
Instantiate(BulletPrefab, transform.position, transform.rotation);
}
}
}