I have two scripts.
rotate gun:
using UnityEngine;
using System.Collections;
public class rotateGun : MonoBehaviour
{
public float rotateSpeed;
public float minRotate, maxRotate;
public float noRotation;
void start() { }
void Update()
{
if (Input.GetKey(KeyCode.D))
{
transform.Rotate(0.0f, 0.0f, -rotateSpeed);
}
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(0.0f, 0.0f, rotateSpeed);
}
}
}
and fireGun:
using UnityEngine;
using System.Collections;
public class FireGun : MonoBehaviour
{
public GameObject shot;
public Transform shotSpawn;
public float fireRate;
private float nextFire;
public float fireSpeed;
private GameObject cloneShot;
public Transform arm;
public float Direction = 0;
void Start () { }
void Update ()
{
if(Input.GetKey(KeyCode.Space) && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
cloneShot = (GameObject)Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
cloneShot.GetComponent<Rigidbody>().velocity = new Vector3(fireSpeed,Direction);
}
if (arm.transform.rotation.z > 0 && arm.transform.rotation.z < 90)
{
Direction += 1;
}
if (arm.transform.rotation.z < 0 && arm.transform.rotation.z >350)
{
Direction -= 1;
}
}
}
in rotateGun i need to limit the rotation of the z axis in side view (90 & 350)
in fireGun i need to fire the bullet in the degree the gun’s rotation on the z axis.
I have tried for weeks to fix these and have not found anything.
Answers are appreciated thoroughly!
Thanks!!