public float moveSpeed = 1.0f;
public GameObject lazer;
public float lazerSpeed = 1.0f;
public float shootDelay = 0.2f;
private bool canShoot = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
transform.position += moveDirection * moveSpeed * Time.deltaTime;
if((Input.GetAxis("FireHorizontal") != 0.0f || Input.GetAxis("FireVertical") != 0.0f) && canShoot)
{
Vector3 shootDirection = new Vector3(Input.GetAxis("FireHorizontal"), Input.GetAxis ("FireVertical"), 0).normalized;
GameObject lazerInstance = Instantiate(lazer, transform.position, Quaternion.LookRotation(shootDirection)) as GameObject;
lazerInstance.rigidbody.AddForce (shootDirection * lazerSpeed, ForceMode.VelocityChange);
canShoot = false;
Invoke ("ShootDelay", shootDelay);
}
}
void ShootDelay()
{
canShoot = true;
}
}
Quaternion.LookRotation works but rotates object so camera can not see sprite because it is turned sideways.