Hello every one, im facing a problem which is senseless. Im very new in unity so maybe i forgot something.
I got this:
using UnityEngine;
using System.Collections;
public class PaddleScript : MonoBehaviour {
float paddleSpeed = 20f;
public GameObject ballPrefab;
GameObject attachedBall = null;
// Use this for initialization
void Start () {
//Instanciar la nueva bola
SpawnBall();
}
void SpawnBall(){
if (ballPrefab == null){
Debug.Log ("No se seleccionado el prefab del GameObject");
return;
}
attachedBall = (GameObject)Instantiate( ballPrefab );
}
// Update is called once per frame
void Update () {
getController();
}
void getController(){
transform.Translate (paddleSpeed * Time.deltaTime * Input.GetAxis("Horizontal"),0,0);
if (attachedBall){
Rigidbody ballRigidBody = attachedBall.rigidbody;
ballRigidBody.position = transform.position + new Vector3(0,0.75f,0);
if (Input.GetButtonDown("LaunchBall")){
ballRigidBody.isKinematic = false;
ballRigidBody.AddForce(300f ,300f,0);
attachedBall = null;
}
}
}
void OnCollisionEnter (Collision col){
foreach (ContactPoint contact in col.contacts){
if ( contact.thisCollider == collider ){
float english = contact.point.x - transform.position.x;
contact.otherCollider.rigidbody.AddForce( 300f * english, 0 , 0);
}
}
}
}
It’s supposed to work (and in fact it does), BUT every time i run the game, console shows the message “No prefab selected in inspector” which i’ve set up for testing purposes. Actually prefab it’s set up in the inspector, so, what’s going on?
Ow i almost forgot it, in the line:
attachedBall = (GameObject)Instantiate( ballPrefab );
monodevelop says that the ballPrefab doesn’t exists in this context
Thanks in advance!