- Home /
2D Grid Question
I found this post which helped me a great deal -
though when I implement this code everything works apart from the mouse over part. I placed a Debug.Log in there and it definitely is not recording the mouse over part?! Any answers?
There are no errors in the code and the names are all spelt correctly i'm lost!
Any help would be appreciated!
//WhateverGrid.js
var gridData : DefenseGrid;
function Start(){
gridData = GameObject.Find("Grid").GetComponent("DefenseGrid");
}
function OnMouseOver(){
gridData.grid[1,2].renderer.material.color = Color.red;
Debug.Log("Mouse over recorded");
renderer.material.color = Color.red;
}
//DefenseGrid.js
var grid : GameObject[,];
var gridSizeX : int;
var gridSizeY : int;
var square : GameObject;
function Start(){
grid = new GameObject[gridSizeX, gridSizeY];
for(var y : int = 0; y < gridSizeY; y++){
for(var x : int = 0; x < gridSizeX; x++){
var s : GameObject = GameObject.Instantiate(square, Vector3(transform.position.x-(x * (square.renderer.bounds.size.x)), transform.position.y+(y * (square.renderer.bounds.size.y)), transform.position.z), Quaternion.identity);
grid[x, y] = s;
Debug.Log("Yeah");
}
}
}
the script is applied to the object that the mouse is over?
and your script is attached to a GUIElement or a game object with a collider, as per the documentation? http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseOver.html
I'm such a dic*....thank you for correcting me Graham!
Your answer
Follow this Question
Related Questions
2d Array persists during multiple game sessions 2 Answers
Highlighting tiles on a hexagonal grid 1 Answer
Creating a 2d array with the Array class 1 Answer
How to make 2d distortion? 2 Answers
Get position from Isometric TileMap 1 Answer