Question by
the_MASTER_x19 · Jun 27, 2017 at 09:11 PM ·
assembly
Missing assembly reference, What do I do?
I'm getting the error: Assets/LeftDoorOpen_Close.cs(31,28): error CS1061: Type object' does not contain a definition for
gameObject' and no extension method gameObject' of type
object' could be found. Are you missing an assembly reference?
What do I do? Here is my code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LeftDoorOpen_Close : MonoBehaviour {
Animator animator;
bool doorOpen;
public object LeftDoorKeyPad { get; private set; }
void Start()
{
doorOpen = false;
animator = GetComponent<Animator>();
}
void OnTriggerStay(Collider LeftDoorKeyPad)
{
if(LeftDoorKeyPad.gameObject.tag == "Player")
{
if (Input.GetKey(KeyCode.X))
{
doorOpen = true;
DropshipLeftDoor("Open");
}
}
}
void OnTriggerExit(Collider LeftDoorKeypad)
{
if (LeftDoorKeyPad.gameObject.tag == "Player") // <-- It's referring to this line.
{
if (Input.GetKey(KeyCode.X))
{
if (doorOpen)
{
doorOpen = false;
DropshipLeftDoor("Close");
}
}
}
}
void DropshipLeftDoor(string direction)
{
animator.SetTrigger(direction);
}
}
Sorry if this is a total noob question but I'm a beginner. ;)
Comment
Answer by Coleclaw199 · Jun 27, 2017 at 11:03 PM
Try this:
Animator animator;
bool doorOpen;
public GameObject LeftDoorKeyPad { get; private set; }
void Start()
{
doorOpen = false;
animator = GetComponent<Animator>();
}
void OnTriggerStay(Collider LeftDoorKeyPad)
{
if(LeftDoorKeyPad.gameObject.tag == "Player")
{
if (Input.GetKey(KeyCode.X))
{
doorOpen = true;
DropshipLeftDoor("Open");
}
}
}
void OnTriggerExit(Collider LeftDoorKeypad)
{
if (LeftDoorKeyPad.tag == "Player")
{
if (Input.GetKey(KeyCode.X))
{
if (doorOpen)
{
doorOpen = false;
DropshipLeftDoor("Close");
}
}
}
}
void DropshipLeftDoor(string direction)
{
animator.SetTrigger(direction);
}
I don't have time to test the code, so I hope it works.
I just tested it, it came with no errors. :] Have a nice day! :]