Hi i’m struggling with an aspect of unity involving inheritance.
I initially assumed the best way to work would be to derive new classes from GameObjects but as they are a sealed class it has throw a little confusion into the way I would work. I then understood that prefabs were essentially the way around this, you could bundle up your own bespoke GameObjects in the form of prefabs (is this correct) now the problem comes when accessing members of instances of those prefabs. I have set up a bit of code which essentially looks like this.
I have tried it with getComponent on (Cube) and (“Cube”) on the instance and it doesn’t show that the isActive bool variable is available for setting.
Thank you in advanced
//----------------------------------------------------------------------------------------
// First Script
//----------------------------------------------------------------------------------------
public class GameItem : MonoBehavior
{
public bool is Active;
}
//----------------------------------------------------------------------------------------
// Second Script ~ Is on a Cube Prefab
//----------------------------------------------------------------------------------------
public class Cube : GameItem
{
isActive = true;
}
//----------------------------------------------------------------------------------------
// Third Script
//----------------------------------------------------------------------------------------
public class CubeEffector : MonoBehavior
{
public GameObject cubePrefab; // Holds a reference to the Cube Prefab
GameObject cubeInstance = Instantiate(cubePrefab, transform.position, transform.localRotation);
if(conditions are met){
cubeInstance.isActive = false;
}
}
wouldnt that just instantiate the cube class without the prefab? i need the prefab because the geometry is part of the prefab ideally cube and the prefab would be the same thing, is there a way to do this? I assumed the best way was to attack a script to the prefab and instantiate the prefab as if you would the class. thank you for your reply btw
– sacredgeometryYou have to look for mainTemplate.gradle, it should be generated in your Assets\Plugins\Android folder if you have checked the Custom Main Gradle Template
– MGamingArtsYT