鼠标控制旋转
private float speed =
100.0f
;
private float
x;
private float
y;
void
Update () {
if(Input.GetMouseButton(
0)){
//
鼠标按着左键移动
y = Input.GetAxis(
"
Mouse X
") * Time.deltaTime *
speed;
x = Input.GetAxis(
"
Mouse Y
") * Time.deltaTime *
speed;
}
else
{ x = y =
0
; }
//
旋转角度(增加)
transform.Rotate( new Vector3(x,y, 0 ));
transform.Rotate( new Vector3(x,y, 0 ));
触屏控制旋转(随着手势移动旋转)
private float x;
private float y;
void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
//Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;(触屏点的位置)
//transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
x = Input.GetTouch(0).deltaPosition.x*Time.deltaTime*speed;
y = Input.GetTouch(0).deltaPosition.y * Time.deltaTime*speed;
transform.Rotate(new Vector3(x, y, 0));
}
else
{
x = y = 0;
}
}
触屏点击事件处理(点击一次)
public GameObject projectile;
public Transform cube;
void Update()
{
public Transform cube;
void Update()
{
if (Input.touchCount > 0&&Input.GetTouch(0).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hitInfo;
if (Physics.Raycast(ray,out hitInfo))
{
GameObject clone = Instantiate(projectile,hitInfo.point,Quaternion.identity) as GameObject;
}
} }
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hitInfo;
if (Physics.Raycast(ray,out hitInfo))
{
GameObject clone = Instantiate(projectile,hitInfo.point,Quaternion.identity) as GameObject;
}
} }
产生的效果,点击正方体cube,会在它的位置上产生projectile;