Need help to find out how to manage space platform system.
I wanted to make a board game and the space platform u land on base what direction you can move. The space tiles will just move you in the direction until you hit another tile, so the platforms don't have to be equally apart from each other. I tried many ways and failed every time trying to find methods to achieve this. I would like to know if I should just make a single script for my spaces or would I have to add different scripts to each one. This kind of movement system is what I am trying to achieve. https://www.youtube.com/watch?v=MtGAQyxW2as
Here is what I was starting with but then found out it won't work like this.
using UnityEngine; using System.Collections;
public class SpaceScript : MonoBehaviour {
public bool Right;
public bool Left;
public bool Up;
public bool Down;
public bool IsSpace;
public GameObject[] players;
public bool PlayerRight;
public bool PlayerLeft;
// Use this for initialization
void Start () {
players = GameObject.FindGameObjectsWithTag ("Player");
PlayerRight = false;
PlayerLeft = false;
}
// Update is called once per frame
void Update () {
Cantmove ();
Canmove ();
}
void OnTriggerEnter2D(Collider2D col){
if (col.gameObject.tag == "Player") {
if (Right != true) {
PlayerRight = false;
}
if (Left != true) {
PlayerLeft = false;
}
}
}
void OnTriggerStay2D(Collider2D col){
}
void OnTriggerExit2D(Collider2D col){
if (col.gameObject.tag == "Player") {
if (Right == true) {
PlayerRight = false;
}
if (Left == true) {
PlayerLeft = false;
}
}
}
void Cantmove(){
if (PlayerRight != true && (Input.GetKey(KeyCode.RightArrow))) {
Debug.Log ("Can't move Right buddy");
}
if (PlayerLeft != true && (Input.GetKey (KeyCode.LeftArrow))) {
Debug.Log ("Can't move Left buddy");
}
}
void Canmove(){
if (PlayerRight == true && (Input.GetKey (KeyCode.RightArrow))) {
// Get the Player from the array thats on a space where they can move right
players[0].transform.Translate(Vector3.right * Time.deltaTime);
}
if (PlayerLeft == true && (Input.GetKey (KeyCode.LeftArrow))) {
// Get the Player from the array thats on a space where they can move right
players [0].transform.Translate (Vector3.left * Time.deltaTime);
}
}
}
Answer by Naphier · May 13, 2016 at 07:17 PM
I'd suggest that you have a script on each tile indicating the available paths.
So I redid the script and this is what I came up with. The problem I am having now if I go back a space I want my counter to go back up. This is what I have going right now...https://gyazo.com/2b9bf9791e5ec36ef6a7d8e424ecb94d
using UnityEngine;
using System.Collections;
public class SpaceScript : $$anonymous$$onoBehaviour {
public bool Right;
public bool Left;
public bool Up;
public bool Down;
public bool ActiveSpace;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D col){
Player.GoRight = false;
Player.GoLeft = false;
Player.GoDown = false;
Player.GoUp = false;
GameObject obj = GetComponent<Collider2D>().gameObject;
col.transform.position = new Vector3 (transform.position.x, transform.position.y, transform.position.z);
if (obj) {
if (ActiveSpace == false) {
Counter.count -= 1;
}
if (ActiveSpace == true) {
Counter.count += 1;
}
}
if (Right != true) {
Player.playerRight = false;
} else
Player.playerRight = true;
if (Left != true) {
Player.playerLeft = false;
} else
Player.playerLeft = true;
if (Down != true) {
Player.playerDown = false;
} else
Player.playerDown = true;
if (Up != true) {
Player.playerUp = false;
} else
Player.playerUp = true;
}
void OnTriggerStay2D(Collider2D col){
}
void OnTriggerExit2D(Collider2D col){
GameObject obj = GetComponent<Collider2D> ().gameObject;
Player.playerUp = false;
Player.playerDown = false;
Player.playerLeft = false;
Player.playerRight = false;
if (obj) {
ActiveSpace = true;
}
}
}
Answer by Jlynn209 · May 13, 2016 at 11:03 PM
Would I be able to write a array like if I step on 3 tiles they will add it to array in the order I step on them and then if I go back in that order it will remove the tiles from the array and give me 1 move back for each one if i step on them in that order? I am new to coding so I don't know much about setting it up and how to write the for loop :(.
Your answer
![](https://koobas.hobune.stream/wayback/20220612080633im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enemy target reference issue 0 Answers
How to make my player knockback when player collision with enemy?My game is 4 direction movement. 1 Answer
How to trigger a cutscene with Unity Timeline 0 Answers
How to make the 2D board game piece move only when the player answers the question correctly? 0 Answers