I have a problem. I can’t get my script to do anything in-game, even though I have everything set. Nothing happens when I press space. Can anyone help me, please?
var ballPrefab:Transform;
var ballSpeed:float = 200;
function Update () {
if(Input.GetKeyDown(KeyCode.Space)){
var ball :Transform= Instantiate(ballPrefab,
transform.Find("SpawnPoint").transform.position,
Quaternion.identity);
ball.rigidbody.AddForce(transform.forward*ballSpeed);
}
Answer: The ball wasn’t set in the hierarchy “player” Ball Prefab. I thought it was enough to set it on the assets tab, straight on the script but it seems that’s useless. Guess my manual isn’t very clear. Thank you everyone!
I believe your error can be fixed easily. I downloaded you project and selecting the player object in the Hierachy panel reveals that the scrip component has a field named ballPrefab. With nothing assigned. What you do is :
Select the Player object in the hierachy panel.
On the asset explorer navigate to the folder that contains the ball.