so basically i need to make a variable that is assigned to a game object. In this case it is the enemy in a basic pong game i’m working on. the game object is named “enemy” btw. I am VERY new to unity and scripting so please go easy on me. Thanks in advance.
Create a JavaScript file and place it on the game object just like any other component. You can create variables for that game object by making variables in that script. Is this what your asking?
You can’t assign arbitrary values directly to a game object, you will need to create a behaviour for the object.
Create a new script file, EnemyBehaviour (for example) and drop it on the game object, as Sericet1 suggested.
Put this in that script:
public int someValue = 0;
Then in the main script, you can access this value by:
public EnemyBehaviour enemy; // swap for whatever you called the class, and drag and drop the enemy into the space in the editor
void Start() {
Debug.Log(enemy.someValue);
}
While I appreciate you said JavaScript, the general idea is the same. I’m not up on Java syntax.