- Home /
How do Code this? AddScore is outdated.
Assets/Scripts/Destroy_By_Contact.cs(23,18): error CS1061: Type Game_Controller' does not contain a definition for AddScore' and no extension method AddScore' of type Game_Controller' could be found. Are you missing an assembly reference?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Destroy_By_Contact : MonoBehaviour { public GameObject explosion; public GameObject playerExplosion; public int scoreValue; public Game_Controller gameController;
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);
}
gameController.AddScore (scoreValue);
Destroy(other.gameObject);
Destroy (gameObject);
}
}
Answer by andyborrell · Dec 05, 2017 at 07:07 PM
If you're following part 3 of the space shooter tutorial then I think you may have missed adding the AddScore method to your game controller class. At time 6:34 in the video you can see the AddScore method being added.
Check that you added this correctly.
Now its stating UnassignedReferenceException: The variable scoreText of Game_Controller has not been assigned. You probably need to assign the scoreText variable of the Game_Controller script in the inspector. Game_Controller.UpdateScore () (at Assets/Scripts/Game_Controller.cs:49) Game_Controller.Start () (at Assets/Scripts/Game_Controller.cs:21) I'm guessing because GuiText is about to be obsolete.
Answer by Jabriel01 · Dec 06, 2017 at 02:26 AM
Thank You! OMGosh! I feel so embarrassed. I put UpdateScore twice in Game_Controller script. SMH
Now its stating UnassignedReferenceException: The variable scoreText of Game_Controller has not been assigned. You probably need to assign the scoreText variable of the Game_Controller script in the inspector. Game_Controller.UpdateScore () (at Assets/Scripts/Game_Controller.cs:49) Game_Controller.Start () (at Assets/Scripts/Game_Controller.cs:21)
I'm guessing because GuiText is about to be obsolete.
Your answer