Skip to content
Snippets Groups Projects
Commit 62958ddd authored by William G. Tresselt's avatar William G. Tresselt
Browse files

Removed prints, added out of bounds check and tweaked check for being grounded

parent 6846c8fd
Branches
No related tags found
No related merge requests found
...@@ -23,12 +23,13 @@ public class ColorSubscriber : MonoBehaviour ...@@ -23,12 +23,13 @@ public class ColorSubscriber : MonoBehaviour
public void notifyColorChange(Color c) public void notifyColorChange(Color c)
{ {
//If all rgb values match, make subscriber interactable
if (c.r == material.color.r && c.g == material.color.g && c.b == material.color.b) if (c.r == material.color.r && c.g == material.color.g && c.b == material.color.b)
{ {
Debug.Log("Subscriber got notified: " + c);
mCollider.enabled = true; mCollider.enabled = true;
material.color = new Color(c.r, c.g, c.b); material.color = new Color(c.r, c.g, c.b);
} }
//Else, gray it out and remove interactibility
else else
{ {
mCollider.enabled = false; mCollider.enabled = false;
......
...@@ -27,6 +27,7 @@ public class ColorChanger : MonoBehaviour ...@@ -27,6 +27,7 @@ public class ColorChanger : MonoBehaviour
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
//Interact with red if pressed 1
if (Input.GetButtonDown(KeyCode.Alpha1.ToString())) if (Input.GetButtonDown(KeyCode.Alpha1.ToString()))
{ {
material.color = Color.red; material.color = Color.red;
...@@ -34,6 +35,8 @@ public class ColorChanger : MonoBehaviour ...@@ -34,6 +35,8 @@ public class ColorChanger : MonoBehaviour
{ {
if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.red); } if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.red); }
} }
//Interact with green if pressed 2
if (Input.GetButtonDown(KeyCode.Alpha2.ToString())) if (Input.GetButtonDown(KeyCode.Alpha2.ToString()))
{ {
material.color = Color.green; material.color = Color.green;
...@@ -42,6 +45,8 @@ public class ColorChanger : MonoBehaviour ...@@ -42,6 +45,8 @@ public class ColorChanger : MonoBehaviour
if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.green); if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.green);
} }
} }
//Interact with blue if pressed 3
if (Input.GetButtonDown(KeyCode.Alpha3.ToString())) if (Input.GetButtonDown(KeyCode.Alpha3.ToString()))
{ {
material.color = Color.blue; material.color = Color.blue;
...@@ -50,6 +55,8 @@ public class ColorChanger : MonoBehaviour ...@@ -50,6 +55,8 @@ public class ColorChanger : MonoBehaviour
if (g!=null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.blue); if (g!=null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.blue);
} }
} }
//Remove all colors if pressed r
if (Input.GetButtonDown(KeyCode.R.ToString())) if (Input.GetButtonDown(KeyCode.R.ToString()))
{ {
material.color = Color.white; material.color = Color.white;
......
...@@ -8,6 +8,7 @@ public class PlayerController : MonoBehaviour ...@@ -8,6 +8,7 @@ public class PlayerController : MonoBehaviour
private CharacterController controller; private CharacterController controller;
private Vector3 playerVelocity; private Vector3 playerVelocity;
private Vector3 playerStartPosition;
public float playerSpeed = 3.0f; public float playerSpeed = 3.0f;
private float playerHeight = 1.0f; private float playerHeight = 1.0f;
...@@ -17,12 +18,13 @@ public class PlayerController : MonoBehaviour ...@@ -17,12 +18,13 @@ public class PlayerController : MonoBehaviour
void Start() void Start()
{ {
controller = gameObject.AddComponent<CharacterController>(); controller = gameObject.AddComponent<CharacterController>();
playerStartPosition = transform.position;
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight); //Checking whether player is touching the ground or not grounded = Physics.Raycast(transform.position, Vector3.down, (playerHeight/2 + 0.1f)); //Checking whether player is touching the ground or not
if (grounded && playerVelocity.y < 0) if (grounded && playerVelocity.y < 0)
{ {
playerVelocity.y = 0f; playerVelocity.y = 0f;
...@@ -40,5 +42,11 @@ public class PlayerController : MonoBehaviour ...@@ -40,5 +42,11 @@ public class PlayerController : MonoBehaviour
//Applying gravity //Applying gravity
playerVelocity.y += G * Time.deltaTime; playerVelocity.y += G * Time.deltaTime;
controller.Move(playerVelocity * Time.deltaTime); controller.Move(playerVelocity * Time.deltaTime);
//If player falling out of bounds, reset position
if(transform.position.y < -3)
{
transform.position = playerStartPosition;
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment