Hello there,
I’m really new to C# scripting (really new here :3)
I’m trying to rotate a mesh with GetMouseButton and has a specific rotation value when i click on it.
My idea is i wan to click the mesh, and make it rotate at a specific value of -90 on the y-axis, and when i click again, i want it to return back the y-axis to 0.
here is my script:
using UnityEngine;
using System.Collections;
public class playerscript : MonoBehaviour {
public float speed;
private Vector3 dir;
// Use this for initialization
void Start () {
dir = Vector3.zero;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton (0)) {
if (dir == Vector3.forward) {
dir = Vector3.left;
transform.Rotate (0, -90, 0);
} else {
dir = Vector3.forward;
transform.Rotate (0, 0, 0);
}
}
float amoutToMove = speed * Time.deltaTime;
transform.Translate (dir * amoutToMove);
}
}
The problem that i’m having is when i hold the mesh, it will rotate in full circle… and i would like to prevent that haha.
The mesh will also move forward when i click the mesh.
Could anyone help me with this? I much appreciate your help
Thank you