Hello, I have a problem, i wrote the Script C# of the ball when it’s moving ecc.
but there’s a problem: Assets/BallControl.cs(56,67): error CS1061: Type UnityEngine.Collider2D' does not contain a definition for
rb’ and no extension method rb' of type
UnityEngine.Collider2D’ could be found (are you missing a using directive or an assembly reference?)
I don’t know what’s does mean, because in all the code it’s all right except for the last part, here’s all the code:
using UnityEngine;
using System.Collections;
public class BallControl : MonoBehaviour {
//dichiarole classi
public float trhust;
public Rigidbody2D rb;
public Vector2 velocity;
//Usethisfor initialization
void Start () {
hi (2.0f);
GoBall ();
}
IEnumerator hi (float secs) {
yield return new WaitForSeconds (secs);
}
void GoBall(){
float rand = Random.Range (0.0f, 100.0f);
if (rand < 50.0f) {
rb.AddForce (new Vector2 (20.0f, 15.0f));
} else {
rb.AddForce (new Vector2 (-20.0f, -15.0f));
}
}
void hasWon() {
var vel = rb.velocity;
vel.y = 0;
vel.x = 0;
rb.velocity = vel;
gameObject.transform.position = new Vector2 (0, 0);
}
void resetBall() {
var vel = rb.velocity;
vel.y = 0;
vel.x = 0;
rb.velocity = vel;
gameObject.transform.position = new Vector2 (0, 0);
hi (0.5f);
GoBall ();
}
void OnCollisionEnter2D (Collision2D coll) {
if (coll.collider.CompareTag (“Player”)) {
var velY = rb.velocity;
velY.y = (velY.y / 2.0f) + (coll.collider.rb.velocity.y / 3.0f);
rb.velocity = velY;
}
}
}