Question by
viktoria_h · Oct 22, 2016 at 08:56 AM ·
scripting problemobject movement
Object moves on itself, how to write an "if statement'?
Hello everyone I'm new to C# I wrote this script to move an object forward-backward, left-right, up-down When I hit play in unity the object starts moving on its own How do I rewrite the 'void Update()' into an if statement?
using UnityEngine; using System.Collections;
public class PlayerControl : MonoBehaviour {
//movement controls variables
public float moveSpeed = 15;
private Vector3 moveDir;
void Start () {
}
void Update () {
//movement
moveDir = new Vector3 (Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical"), Input.GetAxisRaw("Jump") ).normalized;
GetComponent<Rigidbody>().MovePosition (GetComponent<Rigidbody>().position + transform.TransformDirection (moveDir) * moveSpeed * Time.deltaTime);
}
void FixedUpdate() {
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612095154im_/https://answers.unity.com/themes/thub/images/avi.jpg)