- Home /
referencing a gameObject with it's own script
Hello all,
I'm having trouble with something very simple: I want to reference a game object with it's own script.
public class ItemScript : MonoBehaviour
{
public Inventory inventory;
public ItemType type;
public Sprite spriteNeutral;
public Sprite spriteHighlight;
public int maxSize;
private void OnCollisionEnter (Collision other)
{
if (other.gameObject.tag == "Floor")
{
inventory.AddItem(this); //here I want it to add this item
LogManager.AddLine("Object is picked" + _________.name); //here I want it to get the name of this game object
Destroy(gameObject, 3);
}
}
Thanks
I don't understand either. You are already referencing 'this' gameObject for example here Destroy(gameObject, 3);
where you are setting the GameObject to which this svript is attached to, to be destroyed after 3 seconds.
Answer by MilKID · Jun 22, 2017 at 01:48 PM
gameObject.name should work, if not you could always tag it end log the gameObject.tag
Or , if you are trying to reduce engine calls just set a string with the name and log that string.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
this.GameObject - Uses? 1 Answer
Distribute terrain in zones 3 Answers
Inventory AddItem help 1 Answer
Disabling A Script on a GameObject From a Different Script 2 Answers