- Home /
 
error CS0201 im trying to make cube do not rotate
code is this but its not working error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
 using UnityEngine;
 using System.Collections;
 public class NewBehaviourScript : MonoBehaviour
 {
        public float layer = 1;
        public float moveSpeed = 5f;
        public float jump;
        void FixedUpdate ()
     {
         transform.Translate.Rotation.Z == 0;
         transform.Translate.Rotation.Y == 0;
         transform.Translate.Rotation.X == 0;
         if(Input.GetKeyDown(KeyCode.UpArrow))
             layer + 1;
         if (Input.GetKeyDown(KeyCode.DownArrow))
             layer - 1;        
         if (Input.GetKeyDown(KeyCode.W))
             jump = 1;
         if (jump > 0)
             transform.Translate(Vector3.up * moveSpeed * Time.deltaTime);
         if (Input.GetKey(KeyCode.RightArrow))
               transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
         if (Input.GetKey(KeyCode.LeftArrow))
               transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
         }
 
 }
 
              Answer by Mehul-Rughani · Dec 06, 2017 at 12:03 PM
Hello @supersonic79,
You can not use "==" (Double Equal to) for assign value to variable. and if you want transform rotation set to zero then you can do
 transform.rotation = Quaternion.identity;
 
               or
 transform.eulerAngles = Vector3.zero;
 
               And then you have used layer + 1 and layer - 1 instead you have to do like that
 layer = layer + 1;
 or
 layer++;
 or
 layer+=1;
 
               So after modifying all the things your code will be look like this
 public float layer = 1;
     public float moveSpeed = 5f;
     public float jump;
 
     void FixedUpdate ()
     {
         transform.rotation = Quaternion.identity;
         //transform.eulerAngles = Vector3.zero;
         if (Input.GetKeyDown (KeyCode.UpArrow))
             layer += 1;
         if (Input.GetKeyDown (KeyCode.DownArrow))
             layer -= 1;        
         if (Input.GetKeyDown (KeyCode.W))
             jump = 1;
         if (jump > 0)
             transform.Translate (Vector3.up * moveSpeed * Time.deltaTime);
         if (Input.GetKey (KeyCode.RightArrow))
             transform.Translate (Vector3.right * moveSpeed * Time.deltaTime);
         if (Input.GetKey (KeyCode.LeftArrow))
             transform.Translate (Vector3.left * moveSpeed * Time.deltaTime);
     }
 
              Your answer
 
             Follow this Question
Related Questions
How to limit the motion direction of a GameObject? 1 Answer
Exact Rotation Around Another Point Over Time 3 Answers
Separate child rotation 1 Answer
How to make a dynamic bow shot and the arrow to curve and turn correctly when shot? 0 Answers
Physics not applying to the animated object after the animation ends ?! 0 Answers