- Home /
How to reference a GameObject in Unity properly?
I have created the GameObject Character in Unity with sprites however i cant figure out how to reference it in the script so the buttons can cause the Character to jump and move. I already have it working so keys on a keyboard will make the character move but im trying to transfer that code so it can work with the buttons i created instead. Help please, im very new to unity so any advice would be much appreciated!
public class GUItest : MonoBehaviour { void OnGUI() { if(GUI.RepeatButton (new Rect (0,Screen.height - 30,40,25), "Left")) { GameObject.Character.GetComponent().FixedUpdate(); Debug.Log("Clicked left"); } }
And have you tried looking at: http://unity3d.com/learn/tutorials/modules ? Rather than guess the right code, I strongly suggest you invest some time in following a beginner's tutorial.
Answer by haico1992 · Jun 16, 2014 at 07:44 PM
Go to Edit->Project setting->Input You will find a list of name-to-keyboard
Go to Help->Scripting references, search for "Input.GetAxis", everything you need from now on will be in there
Your answer
Follow this Question
Related Questions
C# Check If Gameobject is within Collider 1 Answer
C# Preserving GameObjects' Previous Meshes 1 Answer
Player instantiates Backwords 0 Answers
C# Plane Detecting a Gameobject 1 Answer
C# Reverting GameObject to Original 1 Answer