I’m trying to rotate an object ( a cube for now ) like a moving aeroplane on its z axis and y axis by using a mouse click and mouse drag.
i want the rotations to be like the code below but only on mouse drag.
I’m not sure how to use the mouse drag event a simple pseduocode or directions to do so would be really helpful.
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public float horizontalSpeed = 2.0F;
public float verticalSpeed = 2.0F;
void Update() {
if(Input.GetMouseButton(0)){
float h = horizontalSpeed * Input.GetAxis("Mouse X");
float v = verticalSpeed * Input.GetAxis("Mouse Y");
transform.Rotate(0, h, v);
}
}
}
i made a few changes and tried the following
if(Input.GetMouseButton(0)){
h = horizontalSpeed * Input.GetAxis("Mouse X");
print (h);
//transform.Rotate(0, h, 0);
}
else if(Input.GetMouseButton(1)){
v = verticalSpeed * Input.GetAxis("Mouse Y");
print(v);
//transform.Rotate(0, 0, v);
}
transform.Translate(0,0,speed/20*Time.deltaTime);
}
}
now the cube moves forward and rotates only when i drag the mouse on the right side and vertically upwards rotation but does not respond when i try vertically downwards or on its left…also when i print the val i see -ve values but doesn’t rotate…
~thank you.