Alright. Posted this question a while ago: http://answers.unity3d.com/questions/239078/ios-touch-triggers-the-wrong-object.html
My problem now is similar, yet different.
In my scene is a teapot which spins when tapped and a rocket which launches when tapped.
My problem is that which ever object I tap, the teapot spins AND the rocket launches.
Iv’e tried some stuff to tell the colliders apart, but can’t get it to work. I know someone awesome in here will help me out
Here’s the script for the teapot:
using UnityEngine;
using System.Collections;
public class TouchBlueTeapot : MonoBehaviour {
public Animation m_animation;
// Use this for initialization
void Start () {
Debug.Log("started");
}
// Update is called once per frame
void Update () {
foreach (Touch touch in Input.touches)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
Debug.Log("RAY:" + ray.direction);
if (touch.phase == TouchPhase.Began)
{
Debug.Log("touchphase position:" + touch.position);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 1000))
{
Debug.Log("touched " + hit.transform.name);
gameObject.animation.Play();
}
}
}
}
}
And here’s the code for the rocket:
using UnityEngine;
using System.Collections;
public class Rocket : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
foreach (Touch touch in Input.touches)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
if (touch.phase == TouchPhase.Began)
{
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, 1000))
{
rigidbody.AddForce(0, 1200, 0);
}
}
}
}
}