Hi I’m working on a PCG system but I’ve ran into one problem. I see completely no way of accessing a terrain directly from scripts. the goal is that I want to be able in the script to get the terrain the script are assign to but I can’t use this.gameObject because gameobject sadly cant be casted to terrain. Another thing I tried was Terrain.ActiveTerrain but this don’t work either since it only returns a single terrain, not the one the script is on.
So I really just want to know can I some how access a terrain that a script is assign too directly from the script without setting anything further up?
Yup I know but the thing is that I wanna avoid the fields and assigning everything in the editor, everything should be done by the PCG scripts only. so in other words I’m looking for something similar to this that actually works:
Terrain ter = (Terrain)this.gameObject; // gives Error Cannot convert type 'UnityEngine.GameObject' to 'UnityEngine.Terrain'
I’m proably sounding like a complete douchebag now but that will most likely not work either.
All the plates/terrains the scripts makes have the same name, and there by if I’m correct the “GetComponent” may mix things up? at least it happen for me. An other possibility that I haven’t tried yet, would be to assign different name to the planes but this would require lot of indexing and then you could as well just use the the indexing to look it up but my concerns with that is that it may have a huge memory problems in that.
Again sorry for being a pain in the behind but I’ve already been over those “basic” methods of doing it
GetComponent gets components that are attached to the GameObject; nothing to do with names. Everything that’s attached to an object is a component that can be, er, getted.
wow I’m sorry, The one i was thinking about was GameObject.Find(String); - Total Brain fart right there … The answer was almost too obvious, but I never noticed terrains was a component, but never the less, the GetComponent works well. Thanks again and Sorry for the rudeness