4
0
This repository has been archived on 2023-09-23. You can view files and clone it, but cannot push or open issues or pull requests.
TremendousTaxi/game/Assets/Scripts/GuestBehavior.cs

73 lines
2.2 KiB
C#
Raw Permalink Normal View History

2022-09-25 10:14:23 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Numerics;
using Vector3 = UnityEngine.Vector3;
public class GuestBehavior : MonoBehaviour
{
public CarController cc;
public GameObject boden;
public int g_ID;
private int desX;
private int desY;
private bool arrived = false;
private bool graceperiod = false;
private bool graceperiodLock = false;
private GameObject Boden;
// Start is called before the first frame update
void Start()
{
switch(g_ID) {
case 1:
desX = -47;
desY = -226;
break;
}
if(cc==null)
cc=FindObjectOfType<CarController>();
Boden = Instantiate(boden, transform.position + new Vector3(0,-1,0), UnityEngine.Quaternion.identity);
}
private void OnTriggerStay(Collider other)
{
if (other.tag == "Player" && !graceperiod) {
graceperiod = true;
graceperiodLock = true;
Debug.Log("collision with player detected");
if(arrived == false)
{
Debug.Log("guest picked up, hiding guest model at target");
if(Mathf.Abs(cc.speed) <= 20)
2022-09-25 10:14:23 +02:00
{
GetComponent<MeshRenderer>().enabled = false;
transform.position = new Vector3(desX, -3, desY);
arrived = true;
Boden.transform.position = transform.position + new Vector3(0,5,0);
}
}
else
if(Mathf.Abs(cc.speed) <= 20)
2022-09-25 10:14:23 +02:00
{
Debug.Log("guest arrived at target, showing guest model at target");
GetComponent<Collider>().enabled = false;
Destroy(Boden);
2022-09-25 10:51:31 +02:00
transform.position = new Vector3(desX, 3, desY);
GameObject objectToDisappear = GameObject.Find("Pfeil");
objectToDisappear.GetComponent<Renderer>().enabled = false;
2022-09-25 10:14:23 +02:00
}
}
graceperiodLock = false;
}
void LateUpdate() {
// set graceperiod to false to allow pickup detection after all updates ran
if (!graceperiodLock && graceperiod) {
graceperiod = false;
}
}
}