This script is for football game and this script is applied to the ball.
The purpose of the script is to reset the ball position after every kick kicked by the player…
this script is working successfully to reset the ball position but after the ball is set to its original position its velocity is reaches to zero as written in the code getting zero…but then when the player kicks the ball, it is not moving…i want to make ball move from its position when player kicks it after reset …
i have done its velocity zero because when it is reset, the ball keeps moving even if the player do not kick the ball…
using UnityEngine;
using System.Collections;
public class BallSpawnTest : MonoBehaviour
{
private Vector3 initialPos;
void Start()
{
// Remeber the ball's initial position. Later we will use it to restore the ball after every kick
initialPos = transform.position;
}
void Update ()
{
Debug.Log("update function called");
Reset();
}
private IEnumerator RestartBall()
{
Debug.Log("in restart bal function");
yield return new WaitForSeconds(10);
Debug.Log("in restart bal function2");
transform.position = initialPos;
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
}
public void Reset()
{
StartCoroutine(RestartBall());
Debug.Log("function called");
print(initialPos);
}
}