- Home /
MissingReferenceException Problem
I have a problem when destroy the cage door when moves and i don't know how fix this. I put the code of cage door and lever.
public class DoorCage : MonoBehaviour
{
private bool isOpen = false;
public Transform pos1, pos2;
public float speed;
public Transform startPos;
public float waitAfterDoor;
Vector3 nextPos;
void Start()
{
nextPos = startPos.position;
}
void Update()
{
if (isOpen == true)
{
waitAfterDoor -= Time.deltaTime;
}
if (waitAfterDoor < 0)
{
Destroy(gameObject);
}
}
public void OpenDoor()
{
isOpen = true;
gameObject.SetActive(true);
if (transform.position == pos1.position)
{
nextPos = pos2.position;
}
transform.position = Vector3.MoveTowards(transform.position, nextPos, speed * Time.deltaTime);
}
public void CloseDoor()
{
isOpen = false;
gameObject.SetActive(false);
}
public void ToggleDoor()
{
isOpen = !isOpen;
if (isOpen)
{
OpenDoor();
}
else
{
CloseDoor();
}
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(pos1.position, pos2.position);
}
}
public class Lever : MonoBehaviour
{
Animator animator;
private bool activedoor = false;
[SerializeField]
private DoorCage doorSetActive;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
private void Update()
{
if (activedoor)
{
doorSetActive.OpenDoor();
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Bullet"))
{
animator.Play("Lever_activate");
activedoor = true;
}
}
}
Hi when you copied the scripts in, the lines don't correspond to what's shown in the compile error (Lever 25, DoorCage 43) since you don't have the Using statements. Can you clarify which lines this is happening on?
The lines -Lever 25: doorSetActive.OpenDoor();
-DoorCage 39: gameObject.SetActive(true);
Your answer
Follow this Question
Related Questions
How to double spirte/gameobject/prefab and control the result on those items? 0 Answers
How can i List objects by name but also in small text or big text or any kind ? 1 Answer
Layermask exception 0 Answers
How can i make both two cameras to follow the player but only one with control on player ? 0 Answers
When the mouse is moving and the player is walking why the player is stuttering ? 0 Answers