- Home /
How to rotate a turret around y axis using the mouse ?
Hello! Keep in mind i am very new in scripting. So i have a game with spaceships and they have a turret and i want that turret rotate around the y axis using the mouse.I've tryied something but it was just rotating in one direction,like if i move the mouse to left it was rotating to left but if i move the mouse to right it was rotating to left again.Can anyone help me ? Oh if it is possible to sinq the rotation of the turret with the camera it will be really apreciated.
It would be helpful, if you could post a little bit of your code.
Here is the script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TurretRotation : $$anonymous$$onoBehaviour {
public float speed = 2;
private Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update ()
{
if (Input.GetAxis ("$$anonymous$$ouse X") != 0)
{
transform.Rotate (0, 0, speed);
}
}
}
now i think i know what is the problem, i think this is if (Input.GetAxis ("$$anonymous$$ouse X") != 0) the !=0 but if i don't do this it get me an error Cannot implicitly convert type 'float' to 'bool '