i have searched alot but could not find any refernce across internet. my case is gameobjects are spawning from the top of screen and translating downwords. each gameObject has trigger and a script that translating it. player have to tap on each object to destroy that specific gameobject. i am using raycasting to detect touch on each object. everything working if speed is normal. when object starts to come fast . the gameobject start ignoring touch. any solution for this?
i have to scripts one attach to camera that manage raycasting and other translating tile
Script attached to camera
using UnityEngine;
using System.Collections;
public class RaycastManager: MonoBehaviour {
Touch touch;
public bool stopTime=true;
public float delay,timer;
// Use this for initialization
void Start () {
timer = delay;
}
void Awake()
{
MoveTile.speed = 7f;
}
// Update is called once per frame
void FixedUpdate ()
{
if (Input.touchCount >0) {
//MoveTile.speed = 0f;
touch = Input.GetTouch (0);
RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint ((touch.position)), Vector2.zero);
if (hit.collider.tag == "Pink") {
Destroy (hit.transform.gameObject);
} else if (hit.collider.tag == "Green") {
Destroy (hit.transform.gameObject);
} else if (hit.collider.tag == "Blue") {
Destroy (hit.transform.gameObject);
} else if (hit.collider.tag == "SeaGreen") {
Destroy (hit.transform.gameObject);
} else if (hit.collider.tag == "Purple") {
Destroy (hit.transform.gameObject);
} else if (hit.collider.tag == "Orange") {
Destroy (hit.transform.gameObject);
}
}
}
}
Script attached to each gameobject
using UnityEngine;
using System.Collections;
public class MoveTile : MonoBehaviour {
public float speed;
// Use this for initialization
public void pointerDown ()
{
speed = 0;
gameObject.SetActive (false);
}
// Update is called once per frame
void Update () {
transform.Translate (speed * Vector2.down*Time.deltaTime);
}
}