- Home /
Question by
masterprogamerminecraft · Mar 07 at 09:08 AM ·
playerscripting beginnerdoors
How to Open a Door between two characters at the same time (singleplayer)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorTriggerButton : MonoBehaviour
{
[SerializeField] private DoorAnimated door;
private GameObject player;
private GameObject player2;
public float distance;
private void Update()
{
player = GameObject.FindGameObjectWithTag("Player");
player2 = GameObject.FindGameObjectWithTag("Player2");
distance = Vector2.Distance(player.transform.position, player2.transform.position);
if (distance < 5 && Input.GetKeyDown(KeyCode.E))
{
door.OpenDoor();
}
}
}
captura.png
(167.9 kB)
Comment