Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Jlynn209 · May 12, 2016 at 01:15 AM · 2d gameboardgamerpg-game

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);
     }
 }


}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jlynn209 · May 13, 2016 at 09:50 PM 0
Share

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;
         }
     }
 
 }
     
 

avatar image
0

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 :(.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

57 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How to move to a specific position in 2d game? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges