I am attempting to light up the possible tiles on the grid whilst dragging the finger along the screen…
I have it working well with the mouse thats where the onmouseover and onmousexit comes in handy by lighting up the tile which the mouse is over by enabling the renderer and then changing the color then when the mouse exits it turns it off…I am trying to achieve the same effect on an IOS device…the lighting up works correctly though the squares do not disable themselves when the touch position has left or has moved to another tile…
How would I get the tile to turn off when the finger touch has moved?? Touch.Phase Ended doesn’t work as it lights up the tiles when dragging over them and turns them off all together instead of when the finger is no longer on that tile…sorry about the lengthy description!
#pragma strict
//WhateverGrid.js
var gridData : DefenseGrid;
var myCast : RaycastHit;
var rayLength : float = 300;
static var pointerPosition : Vector2;
function Start(){
gridData = GameObject.Find("Grid").GetComponent("DefenseGrid");
}
function OnMouseOver(){
renderer.enabled = true;
renderer.material.color = Color.red;
}
function OnMouseExit(){
renderer.enabled = false;
}
function Update () {
var touch : Touch;
if (Input.touchCount > 0)
{
touch = Input.touches[0];
if(touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved){
if (Physics.Raycast(Camera.main.ScreenPointToRay(touch.position), myCast, rayLength)) {
var objectHit : GameObject;
objectHit = myCast.collider.gameObject;
if(objectHit.tag == "platform"){
objectHit.renderer.enabled = true;
objectHit.renderer.material.color = Color.red;
}
}
}
}
}