Ejemplo n.º 1
0
    }    //end of instantiate by number

    /*
     *	FUNCTION: Transfroms the location on spline (0.0 to 1.0) to a Vector3 position
     *	PARAMETER 1: Position on spline (0.0 to 1.0)
     *	PARAMETER 2: Is the patch the first or consecutive generated ones
     */
    private Vector3 getPosition(float fLocation, bool bStartPatch)
    {
        if (bStartPatch == true)
        {
            return(hCheckPointsMainCS.getCurrentWSPointBasedOnPercent(fLocation));
        }
        else
        {
            return(hCheckPointsMainCS.getNextWSPointBasedOnPercent(fLocation));
        }
    }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        bMoving = false;

        hCheckPointsMainCS   = (CheckPointsMainCS)GameObject.Find("Player").GetComponent(typeof(CheckPointsMainCS));
        hPatchesRandomizerCS = (PatchesRandomizerCS)GameObject.Find("Player").GetComponent(typeof(PatchesRandomizerCS));
        if (this.transform.parent.parent == null)
        {
            hPathLineDrawerCS = (PathLineDrawerCS)this.transform.parent.GetComponentInChildren(typeof(PathLineDrawerCS));
            patch             = this.transform.parent.gameObject;
        }
        else
        {
            hPathLineDrawerCS = (PathLineDrawerCS)this.transform.parent.parent.GetComponentInChildren(typeof(PathLineDrawerCS));
            patch             = this.transform.parent.parent.gameObject;
        }

        fSpeedPercent = fSpeed / hPathLineDrawerCS.fPathLength;

        isNext  = patch == hPatchesRandomizerCS.getNextPatch();
        isFirst = patch == hPatchesRandomizerCS.getCurrentPatch();
        Vector3 pos;

        if (isNext)
        {
            pos    = hCheckPointsMainCS.getNextWSPointBasedOnPercent(fPercent);
            fAngle = hPatchesRandomizerCS.getNextPatch().transform.eulerAngles.y;
        }
        else
        {
            pos    = hCheckPointsMainCS.getCurrentWSPointBasedOnPercent(fPercent);
            fAngle = hPatchesRandomizerCS.getCurrentPatch().transform.eulerAngles.y;
        }

        offset = this.transform.position - pos;
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (isStoped)
        {
            return;
        }

        if (bMoving)
        {
            fPercent -= fSpeedPercent;

            Vector3 pos;
            if (fPercent <= 0)
            {
                if (isNext)
                {
                    isNext    = false;
                    fPercent += 1f;
                }
                else
                {
                    Destroy(this.gameObject);
                    return;
                }
            }

            if (isNext)
            {
                if (patch == hPatchesRandomizerCS.getNextPatch())
                {
                    pos = hCheckPointsMainCS.getNextWSPointBasedOnPercent(fPercent);
                    //this.transform.localEulerAngles = new Vector3(this.transform.rotation.x, hCheckPointsMainCS.getNextAngle(fPercent),this.transform.rotation.y);
                }
                else if (patch == hPatchesRandomizerCS.getCurrentPatch())
                {
                    pos = hCheckPointsMainCS.getCurrentWSPointBasedOnPercent(fPercent);
                    //this.transform.localEulerAngles = new Vector3(this.transform.rotation.x, hCheckPointsMainCS.getCurrentAngle(fPercent),this.transform.rotation.y);
                }
                else
                {
                    Destroy(this.gameObject);
                    return;
                }
            }
            else
            {
                if (isFirst)
                {
                    if (patch == hPatchesRandomizerCS.getCurrentPatch())
                    {
                        pos = hCheckPointsMainCS.getCurrentWSPointBasedOnPercent(fPercent);
                        //this.transform.localEulerAngles = new Vector3(this.transform.rotation.x, hCheckPointsMainCS.getCurrentAngle(fPercent),this.transform.rotation.y);
                    }
                    else
                    {
                        Destroy(this.gameObject);
                        return;
                    }
                }
                else
                {
                    if (patch == hPatchesRandomizerCS.getCurrentPatch())
                    {
                        Destroy(this.gameObject);
                        return;
                    }
                    pos = hCheckPointsMainCS.getCurrentWSPointBasedOnPercent(fPercent);
                    //this.transform.localEulerAngles = new Vector3(this.transform.rotation.x, hCheckPointsMainCS.getCurrentAngle(fPercent) - (fAngle-hPatchesRandomizerCS.getCurrentPatch().transform.eulerAngles.y),this.transform.rotation.y);
                }
            }

            Vector3 dir   = (pos + offset) - this.transform.position;
            float   angle = PosAngleofVector(dir);
            if (angle > 180.0f)
            {
                angle = angle - 360.0f;
            }

            this.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x, -angle + 180, this.transform.eulerAngles.z);

            //this.transform.Translate(pos+offset - this.transform.position);
            this.transform.position = pos + offset;
        }
        else
        {
            if (Vector3.Distance(GameObject.Find("Player").transform.position, this.transform.position) <= fStartDistance)
            {
                bMoving = true;
            }
        }
    }