Hello,
I have been doing the SpaceShooter game from Unity and completed, but not trying to improve and learn more about the process of building a game. When I call an OnTrigger it works kind of, but when I subtract a life from my player, it actually subtracts 2 the first time. Here is the trigger:
Then in the Game controller I remove the life, which starts at 3. The UpdateScore(), just updates GUIText. Any ideas wahy the count is not working correctly.
public void GameOver()
{
life = --life;
UpdateScore();
if (life > 0)
{
Instantiate(Resources.Load("Player"));
}
if (life <= 0)
{
gameOverText.text = "Game Over";
gameOver = true;
}
}
Here is the other Error I am getting: This is line 49 of DestroyByContact.cs( gamecontroller.GameOver()
ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:239)
UnityEngine.Object.Instantiate (UnityEngine.Object original) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:176)
GameConroller.GameOver () (at Assets/Scripts/GameConroller.cs:59)
DestroyByContact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/DestroyByContact.cs:49)
Thanks for the response, I took a look and I do have them defined I believe. Below is where I declare the values, if I am doing it wrong, please let me know. Then in the Inspector I did not have values, so I added, but still get the error. I removed the Life stuff for now, until I can fix this issue.
public GameObject explosion;
public GameObject playerExplosion;
public GameObject Player;
public int scoreValue;
private GameConroller gamecontroller;
Ran again and still get error:
ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:239)
UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:201)
DestroyByContact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/DestroyByContact.cs:54)
I went through each object that uses the DestroyByConact file and added the reference(Might be wrong term), to the Prefab player and all other items that show up in the inspector, still same error.
lol you changed the code on us. That’s why I couldn’t find the error. Kelso is correct. You dont need to load it from Resources as you already have the prefab linked. You can remove the ‘Player = Resources.Load…’ and just have ‘Instantiate(Player)’ as you loaded the Player unless the Resources.Load(“Player”) is something else than the GameObject player. then I suggest you call them something different. It also seems like maybe ‘resources.load(player)’ doesn’t exist.
THANK YOU!!! Sorry for the change in code, I was messing around and trying to figure it out. Google has a lot of OLD info. Removed the resource.load fixed it. again, thank you for taking the time to respond juicyz and KelsMRK.