Это пример игры 2-го гнева в стиле птицы. Я работаю над кодами сброса. Код сменщика ниже (я изменил некоторые части). Я использую мяч в этом проекте вместо птиц. Итак, я хочу, чтобы мяч был остановлен после того, как бросил новый мяч для катапульты. Но это работает неправильно. Прежде всего. Я написал, если ball count == 0 клонирует объект. Но его близкие клонирование, когда мяч был остановлен. С другой стороны, я не могу использовать клонированный объект для метания. Клонированный объект не на катапульте. Извините за мой плохой английский, но эта проблема моя последняя фаза в этой игре.Unity 3D Object Constantly Cloning
, например https://www.dropbox.com/s/h3gwinw8chyeh59/error.png?dl=0
Это игра обучающая ссылка. http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/making-angry-birds-style-game
using UnityEngine;
using System.Collections;
public class Resetter : MonoBehaviour {
public Rigidbody2D projectile; // The rigidbody of the projectile
public float resetSpeed = 0.025f; // The angular velocity threshold of the projectile, below which our game will reset
private float resetSpeedSqr; // The square value of Reset Speed, for efficient calculation
private SpringJoint2D spring; // The SpringJoint2D component which is destroyed when the projectile is launched
public int BallCount; // I using this value for I need new ball or not
public Rigidbody2D projectileSD; // Ball
void Start()
{
BallCount = 1;
// Calculate the Resset Speed Squared from the Reset Speed
resetSpeedSqr = resetSpeed * resetSpeed;
// Get the SpringJoint2D component through our reference to the GameObject's Rigidbody
spring = projectile.GetComponent <SpringJoint2D>();
}
void Update() {
// If the spring had been destroyed (indicating we have launched the projectile) and our projectile's velocity is below the threshold...
if (spring == null && projectile.velocity.sqrMagnitude < resetSpeedSqr) {
// ... call the Reset() function
// Reset();
if (BallCount == 0);
{
ObjeyiKlonla();
}
}
}
void ObjeyiKlonla() { // Clone object
Rigidbody2D clone;
clone = Instantiate (projectileSD, transform.position, transform.rotation) as Rigidbody2D;
clone.velocity = transform.TransformDirection (Vector3.forward * 1);
BallCount ++;
}
void OnTriggerExit2D (Collider2D other) {
// If the projectile leaves the Collider2D boundary...
if (other.rigidbody2D == projectile) {
// ... call the Reset() function
//Reset();
}
}
void Reset() {
// The reset function will Reset the game by reloading the same level
//Application.LoadLevel (Application.loadedLevel);
BallCount =0;
}
}
Сначала вы должны исправить свою ошибку в Logic. Вы сказали, что уничтожаете весенний компонент. После того, как вы его используете. Но скрипт все еще пытается получить к нему доступ после того, как вы использовали катапульту или даже когда вы начали использовать катапульту. Либо правильно настройте свой пружинный компонент, либо Поворот функции, которую скрипт пытается использовать компонент Spring. – Aizen