【发布时间】:2020-08-06 00:56:29
【问题描述】:
我有一个附加到预制件的脚本,脚本是:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class destroyer : MonoBehaviour
{
Circles circles;
CircleCollider2D collider1;
Collider2D collider2;
private void Start()
{
circles = FindObjectOfType<Circles>();
}
private void OnEnable()
{
collider1 = gameObject.transform.GetChild(0).GetComponent<CircleCollider2D>();
collider2 = gameObject.transform.GetChild(1).GetComponent<Collider2D>();
}
private void Update()
{
if (transform.position.y < 2)
{
Destroy(gameObject);
circles.instantiator();
}
}
void OnTriggerStay2D(Collider2D other)
{
if (collider1.bounds.Contains(other.bounds.max) && collider1.bounds.Contains(other.bounds.min))
{
if (other.bounds.Contains(collider2.bounds.max) && other.bounds.Contains(collider2.bounds.min))
{
if (transform.position.y > 3)
{
Destroy(other.gameObject);
Destroy(gameObject);
circles.instantiator();
}
}
}
}
}
当我实例化预制件时,即使条件为真,if 条件也不会运行。 但是当我将预制件放在场景中并玩游戏时,如果条件根据条件运行良好。我无法弄清楚这是什么问题。
【问题讨论】: