Hi, I have two errors. I am sorry everyone but I am going crazy
CS0118, DestroyByContact.Game controller' is a
field' but a type' was expected and CS10621, Type
object' does not contain a definition for GameOver' and no extension method
GameOver' of type `object' could be found (are you missing a using directive or an assembly reference?). Here is my script { public GameObject explosion; public GameObject playerExplosion; private object Gamecontroller; private object gamecontroller;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Boundary")
{
return;
Debug.Log(other.name);
}
Instantiate(explosion, transform.position, transform.rotation);
if (other.tag == "Player")
{
if ((playerExplosion != null) && (gamecontroller != null))
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
Gamecontroller.GameOver();
gamecontroller = GameObject.GetComponent<Gamecontroller>();
}
Destroy(other.gameObject);
Destroy(gameObject);
}
}
}
Answer by TBruce · May 11, 2016 at 12:41 AM
Both Gamecontroller and gamecontroller are plain UnityEngine objects. They are not components. The first thing you need to do is to replace private object with whatever components they are.
I am sorry @$$anonymous$$avina could you be a little more specific?
You have these two declarations
private object Gamecontroller;
private object gamecontroller;
But you are trying to use them like this
Gamecontroller.GameOver();
GameOver is not a member of object
and then you are doing this
gamecontroller = GameObject.GetComponent();
a) In your code you made Gamecontroller a variable but you are using it as a type in the GetComponent() statement.
b) GetComponent() returns component of Type type if the game object has one attached
c. I do not know what you intentions are with these calls but they may eventually lead to errors as well
Destroy(other.gameObject);
Destroy(gameObject);
I am just pointing out the errors here. I can not give you specifics on what this should be
private object Gamecontroller;
private object gamecontroller;
but let me just say it should look something like this
private [Your Component Here] Gamecontroller;
private [Your Component Here] gamecontroller;
for example
private $$anonymous$$yGameController Gamecontroller;
private $$anonymous$$yGameController gamecontroller;
Place the class name that has the function GameOver() defined in it in place of $$anonymous$$yGameController.
Hey, it is fixed but there is another error CS1061 GameObject' does not contain a definition for gameControllerGameOver' and no extension method
gameControllerGameOver' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?) { public GameObject explosion; public GameObject playerExplosion;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Boundary")
{
return;
}
Instantiate(explosion, transform.position, transform.rotation);
if (other.tag == "Player")
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameObject.gameControllerGameOver (); line 19<
}
Destroy(other.gameObject);
Destroy(gameObject);
}
}
Please click the tick to accept the answer if your question was answered.
Hi, could you help me with the above situation? please, I can not find anything wrong.
Your answer
Follow this Question
Related Questions
Help with Script 0 Answers
Parse issue, despite the data being pulled from database 2 Answers
c# - error CS0103: The name `hit' does not exist in the current context (cardboard switching) 1 Answer
Weapon Swap loop only one way. Any ideas? 0 Answers
Errors in script when trying to play animation clips 1 Answer