Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Help Wanted Simple Input/Rotation Question

Discussion in 'Getting Started' started by kingr8, Nov 30, 2021.

  1. kingr8

    kingr8

    Joined:
    Nov 17, 2021
    Posts:
    1
    I have a 3d object that I've created in a scene, and when a player clicks on it I want it to rotate by 90 degrees, in one direction.

    I'm curious about which methods/classes/event handlers I should use to do this. I'm finding a lot of methods that seem to be relevant, but I don't know exactly which ones to use, or how to call them. OnKeyDown, Transform.Rotate, etc? I understand that each object has euler angles, so all I have to do is change the value of one of the object's current xyz angle position.

    I'm very new to everything to do with Unity, so I'm also wondering about how scripts associate with game objects. If I select a game object and use "Add Component" to associate a script with it, is that script running continuously as long as the object exists in the scene? I presume it does, since each script seems to have a "Start" and "Update" method.

    I'm sorry if these questions seem really basic, but I've spent hours searching through tutorials and everything I find isn't relevant or what I'm looking for.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,739
    I'd recommend doing (not just searching through, but actually doing) some intro tutorials, whether you think they are relevant or not. It will be a much faster way to learn what you need.

    Yes, a script added to a GameObject runs its Update method every frame as long as it is active. That's where you can check OnKeyDown, and if the key of interest is pressed, do something like transform.Rotate(0, 90, 0);
     
unityunity