// Update is called once per frame
    public int CastRay()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity))
        {
            Debug.DrawRay(transform.position, transform.forward * hit.distance, Color.yellow);
            Debug.Log("Did Hit");
            // check if camera is facing the origin
            float rad = Vector3.Angle(transform.forward, Vector3.zero - transform.position.normalized);
            if (rad > m_Deviation)
            {
                // object lost
                id = -1;
                CheckPointManager.instance.StopScanningBar();
                Debug.Log("Camera orientation is not facing the marker");
                CheckPointManager.instance.StartPulseOnLastObject();
                return(-1);
            }

            CheckPointObject col = hit.transform.gameObject.GetComponent <CheckPointObject>();
            if (col != null)
            {
                if (id == -1)
                {// no previous reported hits
                    id = col.m_ID;
                    CheckPointManager.instance.StopScanningBar();
                    Debug.Log("Stopped at ray 1");
                    CheckPointManager.instance.StopPulse(-1);
                    return(col.m_ID);
                }
                else if (col.m_ID == id)
                {
                    return(id);
                }
                else
                {
                    // different object
                    CheckPointManager.instance.StopScanningBar();
                    Debug.Log("Stopped at ray 3");
                    CheckPointManager.instance.StopPulse(id);
                    return(id);
                }
            }
        }
        else
        {
            if (id != -1)
            {
                // object lost
                id = -1;
                CheckPointManager.instance.StopScanningBar();
                Debug.Log("Stopped at no ray");
                CheckPointManager.instance.StartPulseOnLastObject();
                return(-1);
            }
        }

        return(-1);
    }
    public void ReportTrackingObject(Tracking obj)
    {
        Debug.Log("Reported trackable");
        // report start point
        if (start != null)
        {
            foreach (CheckPointObject cp in m_CheckPoints)
            {
                cp.gameObject.SetActive(true);
            }
            return;
        }
        start = obj;

        // Generate DOme of points

        /*
         * function sphere ( N:float,k:int):Vector3 {
         *  var inc =  Mathf.PI  * (3 - Mathf.Sqrt(5));
         *  var off = 2 / N;
         *  var y = k * off - 1 + (off / 2);
         *  var r = Mathf.Sqrt(1 - y*y);
         *  var phi = k * inc;
         *  return Vector3((Mathf.Cos(phi)*r), y, Mathf.Sin(phi)*r);
         * };
         */

        for (uint i = 0; i < m_NumberOfCheckPoints; ++i)
        {
            float            inc   = Mathf.PI * (3f - Mathf.Sqrt(5));
            float            off   = 2.0f / ((float)m_NumberOfCheckPoints);
            float            y     = i * (off / 2);
            float            r     = Mathf.Sqrt(1 - y * y);
            float            phi   = i * inc;
            GameObject       cp    = Instantiate(m_CheckPointPrefab, new Vector3(Mathf.Cos(phi) * r * m_Radius, y * m_Radius, Mathf.Sin(phi) * r * m_Radius), Quaternion.identity);
            CheckPointObject cpobj = cp.GetComponent <CheckPointObject>();
            cpobj.m_ID = m_CheckPoints.Count;
            cp.SetActive(false);
            m_CheckPoints.Add(cpobj);
            m_ScannedList.Add(false);
        }

        StartCoroutine(GenerateCheckPoints());
    }
Exemplo n.º 3
0
 public static void reset()
 {
     checkPointObject = null;
 }
Exemplo n.º 4
0
 public static void save()
 {
     checkPointObject = new CheckPointObject(player.position, Camera.main.transform.position, Inventory.getPoints(), Inventory.getEnemyDead());
 }