Whenever i run my basketball shooting game on my ipad and iphone it crashes right after the ball is shot and the player resets to a shoot another,
var newball;
static var tempBasketBall :Rigidbody;
var pos :Transform[ ];
var ball2 :Rigidbody;
var canControl2 = true;
var destroyTime :int = 6;
var player2 :GameObject;
var b2Parent :Transform;
var yVel :float;
var zVel :float;
function Start()
{
ball2 = Instantiate (tempBasketBall, pos[1].position, pos[1].rotation);
ball2.transform.parent = b2Parent;
}
function Update()
{
var count = Input.touchCount;
if (count > 0)
{
for (i=0; i<count; i++)
{
var touch : Touch = Input.GetTouch(i);
if (touch.phase == TouchPhase.Began)
{
player2.animation.PlayQueued(“aim”);
}
if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
{
player2.animation.PlayQueued(“fire”);
ball2.transform.parent = null;
ball2.useGravity = true;
ball2.velocity = transform.TransformDirection(0, yVel, zVel);
MakeBall2(pos[1]);
DestroyBall(ball2);
canControl2 = false;
player2.animation.PlayQueued(“idle”);
}
}
}
}
function MakeBall2(pos)
{
yield new WaitForSeconds(1);
ball2 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation);
ball2.transform.parent = b2Parent;
canControl2 = true;
}
function DestroyBall(ball:Rigidbody)
{
yield new WaitForSeconds(destroyTime);
Destroy(ball.gameObject);
}
PLEASE LET ME KNOW WHAT TO DO As I am stuck
Also when I change
function MakeBall2(pos)
{
yield new WaitForSeconds(1);
ball2 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation);
ball2.transform.parent = b2Parent;
canControl2 = true;
}
To
function MakeBall2(pos)
{
yield new WaitForSeconds(5);
ball2 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation);
ball2.transform.parent = b2Parent;
canControl2 = true;
}
The crash occurs after 5sec when the ball is shot