Currently working on the Space Shooter game. I know many people have posted about this, but I can’t find the right answer.
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public float tilt;
public Boundary boundary;
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
}
}
When I run this code it says: "type ‘UnityEngine.Component’ does not contain a definition for ‘velocity’" ect ect.
When I convert the ‘rigidbody’ to ‘Rigidbody’ with a capital ‘R’, I get an error saying: “An object reference is required to access non-static member ‘UnityEngine.Rigidbody.veocity’”
Any help would be appreciated,
Dream.