幾個小時以來,我一直試圖找到解決方案。我正在努力學習,但我一直被困在這個問題上。我有隨機移動的紅色生物,我希望它們在與綠色物體碰撞時克隆自己。這是附加到綠色物件的腳本。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reproduction : MonoBehaviour
{
void OnTriggerEnter(Collider col) //Ive tried 'other' also, didnt make a difference
{
Destroy(col.gameObject);
Debug.Log("enter");
//GameObject a = Instantiate(other.GameObject) as GameObject;
//a.transform.position = new Vector2(Random.Range(-2f, 2f), Random.Range(-2f, 2f));
}
}
兩者都有 2D 對撞機,Rigidbody2Ds,對撞機的大小合適,IsTrigger在食物物件上也是如此。我嘗試過動態和運動學的各種組合。沒發生什么事。
uj5u.com熱心網友回復:
也許你應該試試這個:
public void OnTriggerEnter2D(Collider2D col)
{
// do something..
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/480211.html
