- Home /
Doors, need help.
So, basically, i followed a youtube tutorial, and it didn't work. So i decided to move the doors instantly into the wall, after you step near it. I think the object is getting moved, but the texture stays there, because i can walk through it. FPSController is the player, by the way. Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class door1 : MonoBehaviour
{
public Transform Door1;
bool IsOpen;
void Start ()
{
IsOpen = false;
}
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "FPSController")
{
IsOpen = true;
Door1.position = new Vector3(-21, 19, -6);
}
}
void OnTriggerExit(Collider col)
{
if(IsOpen)
{
IsOpen = false;
Door1.position = new Vector3(-21, 19, -2);
}
}
}
Answer by tormentoarmagedoom · Sep 28, 2017 at 08:50 AM
Good day. I dont get what exactly you need. But i give you good practice tips (sry bad english):
First, i supose you declare somewhere (not shown here) that Door1 is the transform of the Door Gameobject.
Second, at OnTRiggerExit, check also if the leaving colider is the player.
Third, What is the door composed of? what components have? how is the collider? it have a rigidBody? Post some screenshot of the inspector with door selected.
Byee :S