RotateAround

Hello to all,

I would like to use the RotateAround function to rotate a cube around the center of the screen.
For this I use the following function:

void onMouseDown()
    {
transform.RotateAround (Vector3.zero, Vector3.up, 30f);
    }

I also tried to use a GameObject that I drag and drop in the inspector (see the code below)

public class rotate : MonoBehaviour {
    public GameObject Plane;

    // Update is called once per frame
    void Update () {
    }  
  

    void onMouseDown()
    {
    Plane.transform.RotateAround (Vector3.zero, Vector3.up, 30f);// * Time.deltaTime);
    }
}

The problem is that the cube doesn’t rotate.

Thank you for your help,

A+

Try OnMouseDown instead of onMouseDown.

C# is case-sensitive. I note that your class is named rotate, with a small “r.” While this will compile and run, the universal convention is to capitalize class names. If you are not used to doing that, it might explain why you missed the capital “O” in OnMouseDown.

There are, at a conservative estimate, probably close to one-hundred-billion-trillion sites on the internet that will advise a person as to how to format their C#. The pages on this from Microsoft match pretty much everyone else’s, although they are surprisingly disorganized and hard to use. The short version is that you use PascalCase (first letter capitalized, then first letter of each new word capitalized, no embedded underscores), for these things:

  • namespaces
  • classes
  • public fields (though many advise against having these at all)
  • properties
  • methods

And you use camelCase (just like PascalCase, but the first letter is lower case) for these things:

  • parameters to methods
  • private fields

Interface names are PascalCase, with an “I” added in front (as in "IEnumerator). (I personally think this is a mistake, but no one is asking me what I think.)

There are a lot more, but those are the ones you need to know to get going. You will have no trouble finding more guidance on this, as it is a topic countless programmers dearly love to talk about.

Hi to all,
I have coded the following code :

    void OnMouseDown()
    {
        transform.RotateAround (Vector3.zero, Vector3.up, 30f * Time.deltaTime * 30);
     }

It was a capitalization problem.

Now the problem is that when I tell a button (UI Button) to rotate a cube, it doesn’t rotate.
I click on the button but it doesn’t respond, it’s as if I clicked for nothing.
Thanks for your help,
A+

I know the feeling.