Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Craft Script Error ReferenceException: Object reference not set to an instance of an object

Discussion in 'Editor & General Support' started by Siymon, Aug 11, 2015.

  1. Siymon

    Siymon

    Joined:
    Aug 11, 2015
    Posts:
    4
    Hello , i have copy a CRAFTING script of SpeedTutor , and all work , but my campfire , didn't disappear after use

    SCRIPT :

    #pragma strict

    var campfirePrefab : Transform;
    var player : GameObject;

    private var canBuild : boolean = true;

    function Start()
    {
    renderer.material.color = Color.green;
    renderer.material.color.a = 0.5;
    }

    function OnTriggerEnter(col : Collider)
    {
    if(col.gameObject.tag == "Terrain" || col.gameObject.tag == "Tree")
    {
    renderer.material.color = Color.red;
    renderer.material.color.a = 0.5;
    canBuild = false;
    }
    }

    function OnTriggerExit (col : Collider)
    {
    if(col.gameObject.tag == "Terrain" || col.gameObject.tag == "Tree")
    {
    renderer.material.color = Color.green;
    renderer.material.color.a = 0.5;
    canBuild = true;
    }
    }

    function Update()
    {
    if(Input.GetKeyDown("b") && canBuild == true)
    {
    Instantiate(campfirePrefab, transform.position, transform.rotation);
    player.GetComponent(Crafting) .campFire.SetActive(false);
    }
    }






    Console :
    ullReferenceException: Object reference not set to an instance of an object
    CampfireBuild.Update () (at Assets/Crafting/CampfireBuild.js:39)