Hi,
I’ve been stuck for weeks. I’m making a 2D classic snake mobile game in C#… but I can’t stop the snake from leaving the screen! I’ve tried to create empty objects and use them as borders, but if the screen resolution changes, the borders will either end outside the screen or inside the screen. I don’t want to limit the screen resolution, I want to stop the player from leaving the screen on ANY DEVICE RESOLUTION… how can I do it?
Here’s a screenshot of my game.
Please… I am very very VERY noob at this… I’d never imagine that it would be so hard to make just a simple thing
Here is my actual Snake Code:
using UnityEngine;
using System.Collections;
public class HeadController : MonoBehaviour {
public bool isPlaying = true;
public float SnakeSpeed = 10.0f;
public bool frontBlocked = false;
public bool rightBlocked = false;
public bool leftBlocked = false;
public bool SnakeAlive = true;
void Awake() {
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void DetectBait() {
}
/*void MoverArriba () {
this.transform.localScale = new Vector3 (1, 1, 1);
this.transform.rotation = Quaternion.Euler (0, 0, 0);
this.transform.position = this.transform.position + new Vector3 (0 ,SnakeSpeed, 0);
this.transform.rotation = Quaternion.Euler (0, 0, 90);
}*/
void CheckTriggerColliders () {
//---------------------checar el frontCollider-------------------
if (GameObject.Find ("frontCollider").GetComponent<FrontCollider> ().EnTrigger== true) {
frontBlocked = true;
}
if (GameObject.Find ("frontCollider").GetComponent<FrontCollider> ().EnTrigger== false) {
frontBlocked = false;
}
//---------------------checar el rightCollider---------------------
if (GameObject.Find ("rightCollider").GetComponent<RightCollider> ().EnTrigger == true) {
rightBlocked = true;
}
if (GameObject.Find ("rightCollider").GetComponent<RightCollider> ().EnTrigger == false) {
rightBlocked = false;
}
//---------------------checar el leftCollider--------------------
if (GameObject.Find ("leftCollider").GetComponent<LeftCollider> ().EnTrigger == true) {
leftBlocked = true;
}
if (GameObject.Find ("leftCollider").GetComponent<LeftCollider> ().EnTrigger == false) {
leftBlocked = false;
}
}
void Advance () {
this.transform.position = this.transform.position + new Vector3 (SnakeSpeed, 0, 0);
}