Question by
chreed96 · Oct 18, 2017 at 01:39 AM ·
androidgameobjectname
Accessing name of object passed from OnTriggerEnter2D
I'mg getting the error
from the codeAssets/enemyNo.js(56,21): BCE0019: 'gameObject' is not a member of 'Object'. "
function OnTriggerEnter2D(obj) {
// Name of the object that collided with the enemy
//public GameObject test;
var name = obj.gameObject.name;
// If the enemy collided with a bullet
if (name == "bullet(Clone)") {
// Destroy itself (the enemy) and the bullet
//shship.AddScore(scoreValue);
Destroy(gameObject);
Destroy(obj.gameObject);
}
// If the enemy collided with the spaceship
if (name == "spaceship") {
// Destroy itself (the enemy) to keep things simple
Destroy(gameObject);
}
}
The code works fine on windows and only gives these errors when I switch to android.I'm not super well-versed with unity, but I'm thinking that it's having problems with either the passed 'obj' or I can't access '.name' from 'obj' or 'obj.gameobject'.
Comment