Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (journeyLength == 0)
        {
            return;
        }
        float now         = Time.time;
        float distCovered = (now - startTime) * this.pipeSpeed;
        float fracJourney = distCovered / journeyLength;

        if (fracJourney < 1.0)
        {
            //Debug.Log ("speed "+pipeSpeed+" dist covered is "+distCovered+" len is "+journeyLength+" now is " + Time.time + " frac is " + fracJourney);
            transform.localPosition = Vector3.Lerp(startPipe, endPipe, fracJourney);
            float   scaley = (float)((fracJourney) * endYScale);
            Vector3 scale  = transform.localScale;
            scale.y = scaley;
            transform.localScale = scale;
        }
        else
        {
            Debug.Log("finished grow at " + transform.localPosition);
            journeyLength = 0;
            if (this.nextPipe != null)
            {
                pipeGrow pg = (pipeGrow)this.nextPipe.GetComponent(typeof(pipeGrow));
                pg.growPipe(this.nextLoc, this.nextSpeed, null, Vector3.zero, 0);
            }
        }
    }
    // determine starting points and distance for growing the pipe from the team prefab to the mixer
    void growTeamPipe()
    {
        Transform      ts         = gameObject.transform.FindChild("teamPrefab");
        SphereCollider sc         = (SphereCollider)ts.GetComponent(typeof(SphereCollider));
        float          teamRadius = sc.radius * ts.localScale.x;
        //Debug.Log ("got team sphere, radius is "+ teamRadius);

        // generate a pulse -- just a quickly expanding sphere
        GameObject    pulse      = Instantiate(Resources.Load("pulsePrefab")) as GameObject;
        pulseBehavior pb         = (pulseBehavior)pulse.GetComponent(typeof(pulseBehavior));
        Matrix4x4     thisMatrix = ts.localToWorldMatrix;
        Vector3       worldPoint = thisMatrix.MultiplyPoint3x4(sc.center);

        pb.doPulse(worldPoint, 15, 1.5f, getRemoteColor());

        // team pipe transform position should be middle of that pipe.
        // find distance between the two positions, and prorate based on radius
        // as a percentage of the distance.
        Transform teamPipe = gameObject.transform.FindChild("teamPipe");
        //Vector3 mixer = transform.position;
        float team2Pipe = Vector3.Distance(ts.localPosition, teamPipe.localPosition);
        float percent   = teamRadius / team2Pipe;
        //Debug.Log ("distance is " + team2Pipe + " radius " + teamRadius + " percent = " + percent);
        Vector3  startPipe = Vector3.Lerp(ts.localPosition, teamPipe.localPosition, percent);
        pipeGrow script    = (pipeGrow)teamPipe.gameObject.GetComponent(typeof(pipeGrow));

        if (script == null)
        {
            Debug.Log("no script on team pipe");
            Debug.Break();
            return;
        }


        sc = (SphereCollider)transform.GetComponent(typeof(SphereCollider));
        //Debug.Log ("got local sphere");
        Transform localPipe = gameObject.transform.FindChild("localPipe");
        //Vector3 mixer = transform.position;
        float mix2Pipe  = Vector3.Distance(ts.localPosition, teamPipe.localPosition);
        float mixRadius = sc.radius * ts.localScale.x;

        percent = teamRadius / team2Pipe;
        //Debug.Log ("local distance is " + mix2Pipe + " radius " + mixRadius + " percent = " + percent);
        Vector3  startLocalPipe  = Vector3.Lerp(sc.center, teamPipe.localPosition, percent);
        pipeGrow localPipeScript = (pipeGrow)localPipe.gameObject.GetComponent(typeof(pipeGrow));

        if (script == null)
        {
            Debug.Log("no script on team pipe");
            Debug.Break();
            return;
        }
        script.growPipe(startPipe, 3.3f, localPipe.gameObject, startLocalPipe, 5.0f);
    }