tree cut event
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class CuttableTree : MonoBehaviour
|
||||
{
|
||||
private Quaternion rotation;
|
||||
public GameObject myPrefab;
|
||||
public GameObject stumpPrefab;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent onCut;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@@ -18,23 +23,15 @@ public class CuttableTree : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Cutter")
|
||||
{
|
||||
Instantiate(myPrefab, transform.position, transform.rotation);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.tag == "Cutter")
|
||||
{
|
||||
rotation = transform.rotation;
|
||||
rotation *= Quaternion.AngleAxis(20, Vector3.up);
|
||||
Instantiate(myPrefab, transform.position, rotation);
|
||||
Instantiate(stumpPrefab, transform.position, rotation);
|
||||
Destroy(gameObject);
|
||||
onCut.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user