- Home /
script pointing to entitys
hi all I've made a script that controls the behavior of the instantiated rigidbody to which is attached. it's basically a OnTriggerEnter, pointing to 2 stats machine, to have access to some variables.
public MagicMachine magicMachine;
public EnemyCurrentStats enemyMachine;
private float power;
private float time0;
private float time1;
private float deltaTime;
private float damage;
void OnTriggerEnter (Collider entity)
{
Debug.Log("collision");
if (entity.gameObject.tag == "Enemy")
{
time1 = Time.time;
power = magicMachine.Power;
deltaTime = time1 - time0;
if (deltaTime <= 0.5)
{
damage = Random.Range(70, 100);
enemyMachine.RemoveLife((int)damage);
Debug.Log(damage);
Destroy(gameObject);
}
else if (deltaTime > 0.5 && deltaTime <= 1)
{
damage = Random.Range(50, 70);
enemyMachine.RemoveLife((int)damage);
Debug.Log(damage);
Destroy(gameObject);
}
else if (deltaTime > 1 && deltaTime <= 1.5)
{
damage = Random.Range(30, 50);
enemyMachine.RemoveLife((int)damage);
Debug.Log(damage);
Destroy(gameObject);
}
else if (deltaTime > 1.5)
{
damage = Random.Range(5, 30);
enemyMachine.RemoveLife((int)damage);
Debug.Log(damage);
Destroy(gameObject);
}
}
else if (entity.gameObject.tag != "Player")
{
Destroy(gameObject);
}
}
when i load the game, if the instantiated object hits something, nothing happens. but if i shoot the gameobject to something tagged as "enemy", in the console it says "object reference not set an instance of an object", so i found that i hadn't choose the two script attached, but here's the problem, i can't choose anything in the prefab's inspector, i can only in the game, when the GameObject is been instantiated. how can i solve this? thanks for help and sorry for my english.
you need to state which line number the error is on. the rest of this comment is pure guesswork without knowing where the error is...
did you set enemy$$anonymous$$achine
to anything?
did you intend to destroy the GameObject
this script is attached to, or the entity it collided with? if the latter, the your Destroy()
should probably be using entity
, not gameObject
.