Hey all.
Im working on a little hobby project. Heres the overall idea.
The scene contains an array of tiles. Everytime I mouse over a tile, it should move slightly downwards and maybe play a sound or something like that. Its not totally fleshed out yet. So I started building it, and I do raycasting from the mouse position to see if im mousing over a tile. The problem is that with they way im doing it, Im raycasting all the damn time, and as soon as I start doing alot of tiles, the framerate drops horribly. I know im doing it wrong, im just not sure what the right way would be. Any help is appreciated. Code is seen below
using UnityEngine;
using System.Collections;
public class MouseRayCast : MonoBehaviour {
public Hashtable ht = new Hashtable();
public Hashtable sht = new Hashtable();
// Use this for initialization
void Awake () {
ht.Add("y",-1.0f);
ht.Add("time",0.5f);
sht.Add("y", 0.0f);
sht.Add("time", 0.5f);
//All this hashtable stuff is because I use iTween to move my tiles upon mousing over
}
// Update is called once per frame
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo,50)){
GameObject myBox;
myBox = hitInfo.transform.gameObject;
iTween.MoveTo(myBox,ht);
}else{
iTween.MoveTo(gameObject,sht);
}
}
}
Another problem is the logic I use to get the tiles to snap back into position once the mouse leaves that tile. The movement isnt very smooth, and tends to get jumpy because I basically have two conflicting iTween calls, causing hysteresis. Any tips on that would be awesome aswell.