- Home /
Make an obect take priority over another when touched?
I have a shooting script that makes it to where when you touch within a specific GameObject's area, you will fire a projectile at that area. This works great, and exactly how I want it to, but when I touch on an enemy who is in the scene, nothing will shoot. I'd like it if there would be a way to prioritize the Shooting Area's collision over the enemy's (make the collider on top of it or something), if it helps there are no events that occur when you touch the enemy.
Here's the script; if (Input.touchCount > 0) {
if (Input.GetTouch (0).phase == TouchPhase.Began) {
if (Time.time > shotStart + shotCooldown)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
if (colliderthing.GetComponent<Collider2D>() == Physics2D.OverlapPoint(touchPos))
{
Vector2 dir = touchPos - (new Vector2(transform.position.x, transform.position.y));
dir.Normalize ();
anim.SetTrigger("Shooting");
// shoot object here
shotStart = Time.time;
}
Your answer
Follow this Question
Related Questions
How can I convert a OnMouseDown() command to a GetTouch input properly? 0 Answers
Raycasting UI elements - Without using Event Triggers 0 Answers
check touch position 2 Answers
How do I move an object with my finger?[C#] 1 Answer
A touch'es state is always Began and the position doesn't change 1 Answer