transform.rotate not functioning

I have an error on my code. I know it’s the right rotate code but why it’s not working? :frowning:

using UnityEngine;
using System.Collections;

public class asd : MonoBehaviour {
   
    public static string Square = Bed.bed;
    public GUIStyle Display;
    public GameObject kahon;
    public float guiPlacementX1;
    public float guiPlacementY1;
   
    void OnGUI()
    {
        if (GUI.Button (new Rect (Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .2f, Screen.height * .3f), "", Display))
        {

            if (int.Parse (Square) == 1)
            {
               
                GameObject asdObject = Instantiate(kahon) as GameObject;
                asdObject.transform.position = new Vector3(0f, 0f, 0f);
                asdObject.transform.Rotate= new Vector3(40f,0,0);

            }
        }
    }
   
}

What do you expect it to do? And what is currently happening?

The gameobject “kahon” should be rotated 40 degrees. Just to see the side of the gameobject. The problem is that it’s not running. There is an error: Assets/asd.cs(22,53): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer

See the docs for how to use Transform.Rotate; what you have is invalid syntax.

–Eric

I tried the codes, but it keeps moving. I just want to make my gameobject face to left when a button is clicked.

I just want to rotate the x axis. :frowning:

If you get compile errors, it is not going to work! You have to check the documentation for the method you are using. You were pointed to that one:

You have to use it like that, otherwise it is not going to work!

I am normally using JavaScript but it should be pretty much the same, I guess.

using UnityEngine;
using System.Collections;

public class asd : MonoBehaviour {

    public static string Square = Bed.bed;
    public GUIStyle Display;
    public GameObject kahon;
    public float guiPlacementX1;
    public float guiPlacementY1;

    void OnGUI()
    {
        if (GUI.Button (new Rect (Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .2f, Screen.height * .3f), "", Display))
        {
         
            if (int.Parse (Square) == 1)
            {
           
                GameObject asdObject = Instantiate(kahon) as GameObject;
                asdObject.transform.position = new Vector3(0f, 0f, 0f);
                asdObject.transform.Rotate(40f, 0f, 0f);

            }
        }
    }

As said i am normally using JavaScript, but i hope this helped you, by the way the error “Assets/asd.cs(22,53): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer” is probably because you use the “int.Parse (Square)” inside the if statement, i think you gotta make a variable to store it and use the variable in the if statement instead.

-Jamcount;

No, that’s still not right at all. Please just read the docs for Transform.Rotate and look at what the code example is doing. :slight_smile:

–Eric

I am sorry, i am used to JavaScript, i am a 14 year old boy, i just tried to help, this is just the way it would work for me in JavaScript. And i really don’t see why it shouldn’t work.

-Jamcount;

Looks like you figured it out. :wink:

–Eric