How to get the Gameobject a script is attached to
I want to have a script attached to a gameobject and rotate the gameobject with it.
I want to initiate the gameobject from a different script (while the instance rotate automatically)
what is the easiest way to get the gameobject the script is attached to (from inside the rotating script)? (c#)
Answer by RudyTheDev · Mar 10, 2016 at 10:50 PM
Literally gameObject
. You want transform
for rotation and stuff.
public class Rotate : MonoBehaviour
{
private void Update()
{
gameObject.name = "Been up for " + Time.realtimeSinceStartup;
transform.position += Vector3.up;
}
}
Answer by Mako-Infused · Mar 10, 2016 at 10:47 PM
http://docs.unity3d.com/ScriptReference/Component-gameObject.html
That would be the easiest way, consider watching the nice basic tutorials for Unity.
Your answer
Follow this Question
Related Questions
Unity C# how to Foreach variable in Model/Contract 0 Answers
Assigning a script as a game object in Dictionary 1 Answer
Can't add Orbital script - "The script needs to derive from MonoBehaviour!" 0 Answers
How do you make a random 2D shape in Unity? 0 Answers
How to make multiple game object work with the same scripts? 0 Answers