- Home /
Question by
dawsongray · Dec 06, 2017 at 02:25 AM ·
scripting problemprogramming
TouchControls/MouseInput HELP PLEASE
I have this script and i would like it to use mouse clicks for movement instead of w a s d.
using UnityEngine; using System.Collections;
public class CowMove : MonoBehaviour {
public Vector3 nextDir;
public float jumpForce=100;
public float speed=5;
public float speedRot=100;
public float rotationOffset;
Rigidbody rb;
public Vector3 curPosition;
void Start(){
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
if(transform.position!= new Vector3(curPosition.x,transform.position.y,curPosition.z) +nextDir)
{
transform.position=Vector3.MoveTowards (transform.position, new Vector3 (curPosition.x, transform.position.y, curPosition.z) + nextDir, speed * Time.deltaTime);
transform.rotation=Quaternion.RotateTowards(transform.rotation,Quaternion.LookRotation(Quaternion.Euler(0,rotationOffset,0)*nextDir),speedRot*Time.deltaTime);
}else{
nextDir = Vector3.zero;
curPosition=transform.position;
curPosition.x = Mathf.Round (curPosition.x);
curPosition.z = Mathf.Round (curPosition.z);
if(Input.GetAxisRaw("Horizontal")!=0) {
nextDir.z = -Input.GetAxisRaw ("Horizontal");
Move();
} else if (Input.GetAxisRaw("Vertical")!=0) {
nextDir.x = Input.GetAxisRaw ("Vertical");
Move();
}
}
}
void Move()
{
rb.AddForce (0, jumpForce, 0);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help me finish my room generator 0 Answers
Static variable work in one script but not in the other 1 Answer
How to make GUI Button a fixed size? 1 Answer