Yeah you have to use () with GetComponent like johne has posted.
If you attach your new script to a game object, within the Update() method you can always get it’s values this way:
this.gameObject
But:
this
Refers to the script.
So you have game objects in your hierarchy and scripts attached to them. To get a script attached to a gameobject you use GetComponent();.To find a gameobject, at least at first, just use GameObject.Find(“objectNameGoesHere”);. You’ll want to eventually switch though to using your game object to find others in the hierarchy like this.gameObject.transform.parent etc etc…
This here:
GameObject
You can never use that in your code, because GameObject is a type of object. You can create a reference to one like this:
GameObject myGameObject;
Now you can do:
myGameObject.name
//or
myGameObject.transform.position
//or
myGameObject.GetComponent<ScriptNameAttachedToGameObject>();
You reference stuff by putting the type, then the name after the type.
So, it looks like you want to be able to create a new wall.
Well you do that like this:
public class WallClass() {
GameObject go_Wall;
//or name it something like that I don't know...then inside of Start or Awake:
//Make sure this method is public so we can grab it and use it in another class:
public void CreateWall() {
go_Wall = new GameObject();
go_Wall.name = "My Wall 1";
}
}
Now from a different script you can access it like this:
public class InputOrSomething() {
public WallClass wallClass; //you can name this something else I don't know.
void Start() {
wallClass = this.gameObject.GetComponent<WallClass>();
}
void Update() {
if(Input.GetKey (KeyCode.Return)) {
wallClass.CreateWall();
}
}
If you attach that script it should create a wall if you hit the enter key. Within the CreateWall() method then you’ll want to put a bunch of information, like look up how to set that wall to be a child in your scene’s hierarchy of a certain empty ‘Walls’ object or something (for organization’s sake).
Look up how to create and attach a mesh renderer to your wall objects. Better yet, look up how to create and instantiate a prefab from your CreateWall() method.
There’s a ton of stuff you can do from there.