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()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
if (other.tag == "Cutter")
|
|
|
|
{
|
|
|
|
rotation = transform.rotation;
|
|
|
|
rotation *= Quaternion.AngleAxis(20, Vector3.up);
|
2022-04-04 13:09:59 +00:00
|
|
|
Instantiate(stumpPrefab, transform.position, rotation);
|
2022-04-04 16:04:09 +00:00
|
|
|
Instantiate(logPrefab, transform.position+new Vector3(0, 1, 0), rotation);
|
2022-04-04 13:09:59 +00:00
|
|
|
onCut.Invoke();
|
2022-04-04 16:04:09 +00:00
|
|
|
Destroy(gameObject);
|
2022-03-28 16:03:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|