init
This commit is contained in:
commit
3b4c6e0ec6
506 changed files with 434142 additions and 0 deletions
68
Assets/Scripts/PortalController.cs
Normal file
68
Assets/Scripts/PortalController.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PortalController : MonoBehaviour{
|
||||
|
||||
[System.Serializable] public enum Direction{Left, Right, Up, Down}
|
||||
[SerializeField] Direction direction = default;
|
||||
|
||||
[SerializeField] Transform exitPos = default;
|
||||
|
||||
|
||||
bool teleporting;
|
||||
PlayerController player;
|
||||
Animator anim;
|
||||
|
||||
void Awake(){
|
||||
anim = GetComponentInParent<Animator>();
|
||||
player = FindObjectOfType<PlayerController>();
|
||||
}
|
||||
|
||||
void OnEnable(){
|
||||
anim.SetBool("Close", false);
|
||||
teleporting = false;
|
||||
}
|
||||
|
||||
void OnTriggerStay(Collider col){
|
||||
if (col.CompareTag("Player")){
|
||||
switch (direction){
|
||||
case Direction.Left:
|
||||
if (Input.GetAxisRaw("Horizontal") < 0 && !teleporting){
|
||||
player.Teleport(exitPos.position);
|
||||
StartCoroutine(ClosePortal());
|
||||
teleporting = true;
|
||||
}
|
||||
break;
|
||||
case Direction.Right:
|
||||
if (Input.GetAxisRaw("Horizontal") > 0 && !teleporting){
|
||||
player.Teleport(exitPos.position);
|
||||
StartCoroutine(ClosePortal());
|
||||
teleporting = true;
|
||||
}
|
||||
break;
|
||||
case Direction.Up:
|
||||
if (Input.GetAxisRaw("Vertical") > 0 && !teleporting){
|
||||
player.Teleport(exitPos.position);
|
||||
StartCoroutine(ClosePortal());
|
||||
teleporting = true;
|
||||
}
|
||||
break;
|
||||
case Direction.Down:
|
||||
if (Input.GetAxisRaw("Vertical") < 0 && !teleporting){
|
||||
player.Teleport(exitPos.position);
|
||||
StartCoroutine(ClosePortal());
|
||||
teleporting = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ClosePortal(){
|
||||
yield return new WaitForSeconds(.25f);
|
||||
anim.SetBool("Close", true);
|
||||
yield return new WaitForSeconds(.5f);
|
||||
transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue