I am creating a program, called Reflective_Door, that, upon detecting that a character has entered a room, called “Reflection”, will close a door behind them.
So far, I have created a simple collision detector in the room, called “Reflection_Trigger”.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reflection_Trigger : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
}
}
I have also started the creation of the script that will detect whether my character has entered Reflection, and close Reflective_Door.
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
public class Reflective_Door : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GameObject.Find("Reflection").GetComponent<Reflection_Trigger>().collision;
}
// Update is called once per frame
void Update()
{
if (collision == true)
{
if (transform.position.x == 0.0f)
{
transform.position = new Vector3(-9.06f, 2.56f, 74.87f);
}
}
}
}
Upon attempting to run the program, I am met with the following errors:
-
Assets/Reflective_Door.cs(12,74): error CS1061: ‘Reflection_Trigger’ does not contain a definition for ‘collision’ and no accessible extension method ‘collision’ accepting a first argument of type ‘Reflection_Trigger’ could be found (are you missing a using directive or an assembly reference?)
-
Assets/Reflective_Door.cs(12,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
-
Assets/Reflective_Door.cs(18,13): error CS0103: The name ‘collision’ does not exist in the current context
With this information in mind, what should I create to allow for Reflective_Door to properly detect the collision in Reflection_Trigger and act upon it?
I am new to Unity, so any help is appreciated. Thank you!