- Home /
Question by
GentleRaptor · Jul 16, 2015 at 08:38 AM ·
variablefunctionnon-static
An object reference is required to access non-static member
using UnityEngine;
using System.Collections;
public class EnemyHealthScript : MonoBehaviour {
public int hp = 5;
public bool isEnemy = true;
void OnTriggerEnter2D (Collider2D collider) {
ShotScript shot = collider.gameObject.GetComponent<ShotScript>();
if (shot != null)
{
if (shot.isEnemyShot != isEnemy)
{
hp -= shot.damage;
Destroy(shot.gameObject);
if (hp <= 0)
{ SpecialEffectsHelper.Instance.Explosion(transform.position);
SoundEffectsHelper.Instance.MakeEnemyExplosionSound();
AddReduceMoney.cam.GetComponent<playerMoney>().addMoney (5);
Destroy(gameObject);
}
}
}
}
}
This isn't working, as the title says, and i don't know how to fix it
Comment
I suppose the error is on this line ?
AddReduce$$anonymous$$oney.cam.GetComponent<player$$anonymous$$oney>().add$$anonymous$$oney
as the error says it seems cam is not a static member of your "AddReduce$$anonymous$$oney" class.
maybe use GameObject.Find() to get the reference of the cam