实例化一次
Instantiate once
我知道这是一个常见的问题,但是,我发誓我做了我必须做的,所以我求助于你们告诉我我的工作有什么问题。
我必须在一个对象被另一个对象抛出后在该对象上方生成一个“指示器,所以我有一个代码告诉系统在另一个对象上方实例化该对象作为指示,在 velocity.magnitude 的主要对象变为 0 并保证仅在我放入 bool 以确保我的条件后才实例化,现在实例化对象在我的项目加载后立即实例化一次并且处于真正错误的位置(因为我的对象的第一个状态仍然是 ) 甚至得到我的位置并确保只有在我的最后一个位置 - 我的实际位置不等于 0 时才开始实例化过程,问题仍然存在。我知道它不够清楚所以问我我会回答,这是我的代码:
public bool isCreated = false;
public Vector3 lastPosition;
void Update()
{
if (!isCreated)
{
if ((gameObject.GetComponent<Item>().name =="blue" ||
gameObject.GetComponent<Item>().name =="green")&&
GameObject.Find("blue").GetComponent<Rigidbody2D>().velocity.magnitude == 0 &&
(gameObject.transform.position - lastPosition != null))
{
Instantiate (indice, new Vector3 (gameObject.transform.localPosition.x ,
gameObject.transform.localPosition.y + 2,
gameObject.transform.localPosition.z),
Quaternion.identity);
isCreated=true;
}
// step3 = true;
}
![enter image description here][1]}
void start()
{
lastPosition = gameObject.transform.position;
}
更新条件:
(gameObject.transform.position - lastPosition != null)
收件人:
(gameObject.transform.position - lastPosition != default(Vector3))
或者可能:
(lastPosition != null)
我不确定你试图从你发布的代码中检查什么。
我知道这是一个常见的问题,但是,我发誓我做了我必须做的,所以我求助于你们告诉我我的工作有什么问题。
我必须在一个对象被另一个对象抛出后在该对象上方生成一个“指示器,所以我有一个代码告诉系统在另一个对象上方实例化该对象作为指示,在 velocity.magnitude 的主要对象变为 0 并保证仅在我放入 bool 以确保我的条件后才实例化,现在实例化对象在我的项目加载后立即实例化一次并且处于真正错误的位置(因为我的对象的第一个状态仍然是 ) 甚至得到我的位置并确保只有在我的最后一个位置 - 我的实际位置不等于 0 时才开始实例化过程,问题仍然存在。我知道它不够清楚所以问我我会回答,这是我的代码:
public bool isCreated = false;
public Vector3 lastPosition;
void Update()
{
if (!isCreated)
{
if ((gameObject.GetComponent<Item>().name =="blue" ||
gameObject.GetComponent<Item>().name =="green")&&
GameObject.Find("blue").GetComponent<Rigidbody2D>().velocity.magnitude == 0 &&
(gameObject.transform.position - lastPosition != null))
{
Instantiate (indice, new Vector3 (gameObject.transform.localPosition.x ,
gameObject.transform.localPosition.y + 2,
gameObject.transform.localPosition.z),
Quaternion.identity);
isCreated=true;
}
// step3 = true;
}
![enter image description here][1]}
void start()
{
lastPosition = gameObject.transform.position;
}
更新条件:
(gameObject.transform.position - lastPosition != null)
收件人:
(gameObject.transform.position - lastPosition != default(Vector3))
或者可能:
(lastPosition != null)
我不确定你试图从你发布的代码中检查什么。