tree cut event

This commit is contained in:
2022-04-04 16:09:59 +03:00
parent 8e50da0a93
commit 51d75b196d
3 changed files with 389 additions and 265 deletions

View File

@@ -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();
}
}
}