Quantcast
Channel: Questions in topic: "left"
Viewing all articles
Browse latest Browse all 135

How to turn your object left and right

$
0
0
I want my cube to turn left and right while moving my cube ahead my code for turning left in every state of cube , code is as follows using UnityEngine; using System.Collections; void Update () { transform.position += transform.forward * speed * Time.deltaTime; if (Input.GetKeyDown(KeyCode.LeftArrow)) { if (transform.rotation.y == 0) { transform.rotation = Quaternion.Euler(0, -90 , 0); } else if (transform.rotation.y == -90) { transform.rotation = Quaternion.Euler(0, -180 , 0); } else if (transform.rotation.y == -180) { transform.rotation = Quaternion.Euler(0, -270 , 0); } transform.Rotate(Vector3.left * Time.deltaTime * speed ); } } it works till for the first left turn then when again i press left arrow key nothing happens

Viewing all articles
Browse latest Browse all 135

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>