I’ve been looking around for ages trying to find a way to do this, but every single time I try it, I always get the inspector showing me several errors that shouldn’t be there because everything is defined in the way I’ve seen them be. So, I’ve come here in hopes that someone can help me. All I want is my targetCount variable to be shared from my Bullet script to my Progression one.
Please note that both of these scripts are on my “Player” Game object.
Also, please note that I’m using version 5 of Unity and that the errors that I am currently getting from the inspector are all referring to my Progression script and they are:
the name “thePlayer” does not exist in the current context.
the name “targetCount” does not exist in the current context.
Here is everything you need to know from my Bullet script:
using UnityEngine; using System.Collections; public class Bullet : MonoBehaviour public int targetCount = 0; void OnCollisionEnter (Collision collision) if (collision.gameObject.tag == "Enemy") Destroy (gameObject); collision.gameObject.tag = "Untagged"; Instantiate(fireEffect, collision.transform.position, Quaternion.identity); targetCount = targetCount + 1;
Here is everything you need to know from my Progression script:
using UnityEngine; using System.Collections; using UnityEngine.UI; public class Progression : MonoBehaviour void Start () GameObject theplayer = GameObject.Find ("Player"); Bullet bullet = thePlayer.GetComponent<PlayerScript> (); bullet.targetCount = targetCount;
Oh, and don’t worry about the parsing errors