Heroes_of_Hiis/Assets/Project Files/Scripts/Arlo/CuttableTree.cs

54 lines
1.1 KiB
C#
Raw Normal View History

2022-03-28 16:03:33 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2022-04-04 13:09:59 +00:00
using UnityEngine.Events;
2022-03-28 16:03:33 +00:00
public class CuttableTree : MonoBehaviour
{
private Quaternion rotation;
2022-04-04 13:09:59 +00:00
public GameObject stumpPrefab;
2022-04-04 16:04:09 +00:00
public GameObject logPrefab;
2022-04-04 13:09:59 +00:00
[SerializeField]
private UnityEvent onCut;
2022-03-28 16:03:33 +00:00
// Start is called before the first frame update
void Start()
{
2022-04-11 15:46:10 +00:00
2022-03-28 16:03:33 +00:00
}
// Update is called once per frame
void Update()
{
2022-04-11 15:46:10 +00:00
2022-03-28 16:03:33 +00:00
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Cutter")
{
2022-05-16 14:47:54 +00:00
Cut();
2022-04-11 15:46:10 +00:00
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Cutter")
{
2022-05-16 14:47:54 +00:00
Cut();
2022-03-28 16:03:33 +00:00
}
2022-04-11 15:46:10 +00:00
2022-03-28 16:03:33 +00:00
}
2022-05-16 14:47:54 +00:00
public void Cut()
{
Debug.LogWarning("CUT");
rotation = transform.rotation;
rotation *= Quaternion.AngleAxis(20, Vector3.up);
Instantiate(stumpPrefab, transform.position, rotation);
Instantiate(logPrefab, transform.position + new Vector3(0, 1, 0), rotation);
onCut.Invoke();
Destroy(gameObject);
}
2022-03-28 16:03:33 +00:00
}