Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by 80ProofGaming · Jan 13, 2015 at 10:41 AM · c#gridrpgturn-based

Creating an Interactable Grid for Tactics Game (C#)

I'm making a tactics based RPG along the vein of Final Fantasy Tactics. The first thing I attempted was getting some code together that would create an interactive grid that would sit over the ground and make it easier to handle movement. I was new so I tried to understand someone else's script instead of trying to figure out my own.

The script I found works, but it's time to script my player movement phase and I don't know how to display to the player how far they can move. I have a variable for it but I don't know how to take that variable and change the color of just the squares which the player can reach. The code also doesn't handle elevation at all. I can't change the height of specific cubes. I think I need a new system. Perhaps if I set out the cubes manually and assigned each of them a value, I could then interact with them that way? Any and all advice would be immensely appreciated. Below is my script as it exists now:

In my manager script:

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class Manager : MonoBehaviour { public GameObject TilePrefab; public int mapSize = 11; List map = new List ();

 // Use this for initialization
 void Start () {
     generateMap ();   
 }
    
 // Update is called once per frame
 void Update () {

 }

 void generateMap(){
     map = new List<List<Tile>> ();
     for (int i = 0; i < mapSize; i++) {    //i and j are the two values on the eventual vector2
         List <Tile> row = new List<Tile> ();
         for (int j = 0; j < mapSize; j++) {
             Tile tile = ((GameObject)Instantiate (TilePrefab, new Vector3 (i - Mathf.Floor (mapSize / 2), 0, -j + Mathf.Floor (mapSize / 2)), Quaternion.Euler (new Vector3 ()))).GetComponent<Tile> ();
             tile.gridPosition = new Vector2 (i, j);
             row.Add (tile);
         }
         map.Add (row);
     }
 }

} [/code]

In my Tile script:

using UnityEngine;

using System.Collections;

public class Tile : MonoBehaviour {

 public Vector2 gridPosition = Vector2.zero;
 // Use this for initialization
 void Start () {
    
 }
   
 // Update is called once per frame
 void Update () {
    
 }
 void OnMouseEnter(){
     transform.renderer.material.color = Color.blue;
     Debug.Log ("my position is (" + gridPosition.x + "," + gridPosition.y);
 }
 void OnMouseExit(){
     transform.renderer.material.color = Color.white;
 }

}[/code]

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Braza · Apr 09, 2015 at 11:41 AM

You're doing about right with the tile script. You just need to add some methods there to flag it as "within movement range" and change its color just like in the OnMouseEnter.

As for manager, I don't like List < List < Tile > >. You need something you can access by index like array or map if your coordinate is a struct.

So it could work like this: Player notifies Manager about his desire to move. Manager calculates all possible coordinates player can reach, iterates over them and notifies them that they belong to reachable area.

Pseudocode would be like

 Manager:MoveArea(Player,ActionPoints)
 {
     Tile reachcbleTiles[] = Reachcble(Player.Tile, ActionPoints); 
     foreach( Tile t in reachableTiles)
     {
         t.SetReachable(true);
     }
 }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Turn Order 2 Answers

movement 2d in a grid 3 Answers

Distribute terrain in zones 3 Answers

Looking for RPG system (look inside) 0 Answers

Camera look position is always fixed.. need help. 3 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