https://www.dropbox.com/s/h3gwinw8chyeh59/error.png?dl=0
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;
}
}
答案 0 :(得分:1)
试试这个。
void Update(){
if(projectile.GetComponent <SpringJoint2D>() && projectile.velocity.sqrMagnitude < resetSpeedSqr)
{
if (BallCount <= 0 );
{
ObjeyiKlonla();
}
}
}