Need to count last mouse position, how to do it?
Tile.cs
using UnityEngine;
using System.Collections;
public class Tile : MonoBehaviour {
public Texture[] texture;//laikinai
public Material mat; //laikinai
public Vector3 gridPosition = Vector3.zero;
public Vector3 lastGridPosition = Vector3.zero;
void Start () {
mat = renderer.material;
mat.mainTexture = texture [0];
}
void Update()
{
}
void OnMouseEnter() {
float X1 = gridPosition.x;
float Y1 = gridPosition.y;
float X2 = lastGridPosition.x;
float Y2 = lastGridPosition.y;
//Cia kad judetu ne istrizai
if (X1*X1 > Y1*Y1){
new Vector2 (X1,0);
} else {
new Vector2 (0,Y1);
}
//Debug.Log("my position is " + gridPosition.x + "," + gridPosition.z);
//Cia kad sektu peles bisena lentoj
GameManager.instance.moveCurrentPlayer(this);
//nereikia
lastGridPosition.x = gridPosition.x + transform.position.y;
lastGridPosition.y = gridPosition.y + transform.position.z;
if (X1<X2 && Y1==Y2){
mat.mainTexture = texture [1];
}else if(X1>X2 && Y1==Y2){
mat.mainTexture = texture [2];
}else if(X1==X2 && Y1<Y2){
mat.mainTexture = texture [3];
}else if(X1==X2 && Y1>Y2){
mat.mainTexture = texture [4];
}
//Debug.Log("my position was " + lastGridPosition.x + "," +lastGridPosition.y);
//Debug.Log("Transform position" + transform.position.x + "," + transform.position.y + "," + transform.position.z);
Debug.Log("X And Y " + X1+ ","+ X2+ "," +Y1+ "," +Y2);
}
void OnMouseExit() {
}
void OnMouseDown() {
}
}
GameManager.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour {
public static GameManager instance;
public GameObject TilePrefab;
public GameObject UserPlayerPrefab;
public int mapLength = 9;
public int mapHeigth = 7;
List <List<Tile>> map = new List<List<Tile>>();
List <Player> players = new List<Player>();
int currentPlayerIndex = 0;
void Awake() {
instance = this;
}
// Use this for initialization
void Start () {
generateMap();
generatePlayers();
}
// Update is called once per frame
void Update () {
players[currentPlayerIndex].TurnUpdate();
}
public void nextTurn() {
if (currentPlayerIndex + 1 < players.Count) {
currentPlayerIndex++;
} else {
currentPlayerIndex = 0;
}
}
public void moveCurrentPlayer(Tile destTile) {
players[currentPlayerIndex].moveDestination = destTile.transform.position + 0.95f * Vector3.up;
}
void generateMap() {
map = new List<List<Tile>>();
for (int i = 0; i < mapLength; i++) {
List <Tile> row = new List<Tile>();
for (int j = 0; j < mapHeigth; j++) {
Tile tile = ((GameObject)Instantiate(TilePrefab, new Vector3(i - Mathf.Floor(mapLength/2),0, -j + Mathf.Floor(mapHeigth/2)), Quaternion.Euler(new Vector3(0,180,0)))).GetComponent<Tile>();
tile.gridPosition = new Vector3(i,0,j);
tile.lastGridPosition = new Vector3 (i,0,j);
row.Add (tile);
}
map.Add(row);
}
}
void generatePlayers() {
UserPlayer player;
player = ((GameObject)Instantiate(UserPlayerPrefab, new Vector3(0 - Mathf.Floor(mapLength/2),0.95f, -0 + Mathf.Floor(mapHeigth/2)), Quaternion.Euler(new Vector3(0,180,0)))).GetComponent<UserPlayer>();
players.Add(player);
//
// player = ((GameObject)Instantiate(UserPlayerPrefab, new Vector3((mapLength-1) - Mathf.Floor(mapLength/2),1.5f, -(mapHeigth-1) + Mathf.Floor(mapHeigth/2)), Quaternion.Euler(new Vector3(0,180,0)))).GetComponent<UserPlayer>();
//
// players.Add(player);
//
// player = ((GameObject)Instantiate(UserPlayerPrefab, new Vector3(4 - Mathf.Floor(mapLength/2),1.5f, -4 + Mathf.Floor(mapHeigth/2)), Quaternion.Euler(new Vector3(0,180,0)))).GetComponent<UserPlayer>();
//
// players.Add(player);
// AIPlayer aiplayer = ((GameObject)Instantiate(AIPlayerPrefab, new Vector3(6 - Mathf.Floor(mapSize/2),1.5f, -4 + Mathf.Floor(mapSize/2)), Quaternion.Euler(new Vector3()))).GetComponent<AIPlayer>();
//
// players.Add(aiplayer);
}
}