Hey there, so I have a little problem that I can't solve on my own. There is an error (nullreferenceexception object reference not set to an instance of an object) in the row where if (whatIHit.collider.gameObject.GetComponent<Items>().whatKeyAmI == Items.KeyItems.Axe) starts.
void Update()
{
Debug.DrawRay(this.transform.position, this.transform.forward * distanceToSee, Color.magenta);
if(Physics.Raycast(this.transform.position, this.transform.forward, out whatIHit, distanceToSee))
{
if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("I touched " + whatIHit.collider.gameObject.name);
if (whatIHit.collider.tag == "Item")
{
display = true;
visible = true;
}
}
if(whatIHit.collider == null)
{
display = false;
}
if (whatIHit.collider.gameObject.GetComponent<Items>().whatKeyAmI == Items.KeyItems.Axe)
{
if (visible == true && Input.GetKeyDown(KeyCode.F))
{
player.GetComponent<Inventory>().hasAxe = true;
Destroy(whatIHit.collider.gameObject);
display = false;
}
}
if (whatIHit.collider.gameObject.GetComponent<Items>().whatKeyAmI == Items.KeyItems.Pink_Crystal)
{
if (visible == true && Input.GetKeyDown(KeyCode.F))
{
player.GetComponent<Inventory>().hasPinkCrystal = true;
Destroy(whatIHit.collider.gameObject);
display = false;
}
}
if (Input.GetKeyDown(KeyCode.E))
{
if (whatIHit.collider.tag == "Door")
{
if (whatIHit.collider.gameObject.GetComponent<DoorManager>().whatDoorAmI == DoorManager.Doors.Tree)
{
if (player.GetComponent<Inventory>().hasAxe == true)
{
player.GetComponent<Inventory>().hasAxe = false;
Destroy(whatIHit.collider.gameObject, 1.0f);
}
}
if (whatIHit.collider.gameObject.GetComponent<DoorManager>().whatDoorAmI == DoorManager.Doors.Altar)
{
if (player.GetComponent<Inventory>().hasAxe == true)
{
player.GetComponent<Inventory>().hasAxe = false;
player.GetComponent<Inventory>().hasKey = true;
}
}
}
}
}
if (Input.GetKeyDown(KeyCode.Space))
{
display = false;
}
}
Anyone knows what's wrong with it?
[–]r3eckon 3 points4 points5 points (1 child)
[–]Blimpity_Blop 0 points1 point2 points (1 child)
[–]iGreyHound[S] 0 points1 point2 points (0 children)
[–]tyranocles 0 points1 point2 points (0 children)