I am editing my player movement code, and I broke it. Can someone help me fix it?
The errors I get are,
“An object reference is required to access non - static member ‘PlayerMovement.Boundary.xMin’”
“An object reference is required to access non - static member ‘PlayerMovement.Boundary.xMax’”
“An object reference is required to access non - static member ‘PlayerMovement.Boundary.yMin’”
“An object reference is required to access non - static member ‘PlayerMovement.Boundary.yMax’”
My code is,
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
[System.Serializable]
public class Boundary
{
public float xMin, xMax, yMin, yMax;
}
// Variables
private float moveHorizontal;
private float moveVertical;
public float speed;
public Rigidbody2D rb;
public Boundary boundary;
void Awake()
{
rb = GetComponent<Rigidbody2D> ();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector2
(
Mathf.Clamp(rb.position.x, Boundary.xMin, Boundary.xMax),
Mathf.Clamp(rb.position.y, Boundary.yMin, Boundary.yMax)
);
}
}
Can someone give some ideas as to what might be going wrong? Thanks for the help!