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

@@ -111,4 +111,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1ed5d27829838ec42b4be1d601b4dadc, type: 3}
m_Name:
m_EditorClassIdentifier:
myPrefab: {fileID: 108507113624723981, guid: eebb56c82efbd8d4bb0eb6bd925a0e9d, type: 3}
stumpPrefab: {fileID: 108507113624723981, guid: eebb56c82efbd8d4bb0eb6bd925a0e9d,
type: 3}
onCut:
m_PersistentCalls:
m_Calls: []

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