В моём проэкте, когда я рубаю дерево, то объект который должен "спавнится" в нём(при этом дерево исчезает) вот только оно "спавнится" намного выше объекта!
Вот скрипт Дерева
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HPwood : MonoBehaviour
{
public float hp;
public GameObject[] Spawn;
private void Update()
{
if(hp < 0)
{
for(int i = 0; i < Spawn.Length; i++)
{
Vector3 v3 = new Vector3(transform.position.x, transform.position.y + (Spawn[i].transform.localScale.y + i), transform.position.z);
Instantiate(Spawn[i], v3, Quaternion.identity);
}
Destroy(gameObject);
}
}
}
![5c6325c2525d2933554604.png](https://habrastorage.org/webt/5c/63/25/5c6325c2525d2933554604.png)
![5c632665a4e94829948220.png](https://habrastorage.org/webt/5c/63/26/5c632665a4e94829948220.png)
на всякий случий скрипт топора!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Axe : MonoBehaviour
{
RaycastHit hit;
public AnimationClip anim;
private void Update()
{
if (Input.GetButtonDown("Fire1"))
{
if(Physics.Raycast(transform.parent.transform.position, transform.parent.transform.transform.forward, out hit, 10))
{
if(hit.collider.tag == "Tree")
{
hit.collider.gameObject.GetComponent<HPwood>().hp -= 5;
}
}
}
}
}