private void Update()
    {
        if (collidingWithSolid)
        {
            state = GameObject.Find("Flapper model").GetComponent <JellyBone>().state;
            if (state != FlapperState.solid)
            {
                collidingWithSolid   = false;
                currentSpeed         = speed;
                currentRotationScale = rotationScale;
            }
        }

        if (stop)
        {
            stunTimeTemp -= Time.deltaTime;
            if (stunTimeTemp <= 0)
            {
                stop          = false;
                light.enabled = true;
            }
        }
        else
        {
            ManageRobotPosition();
        }
    }
    public void SetState(FlapperState newState)
    {
        state = newState;
        if (state != FlapperState.solid)
        {
            rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
            if (coreCollider)
            {
                coreCollider.enabled = false;
            }
        }
        else             // solid
        {
            rigidbody.constraints = RigidbodyConstraints.FreezeAll;
            if (!isRoot)
            {
                coreCollider.enabled = true;
                coreCollider.center  = Quaternion.Inverse(core.transform.rotation) * ((transform.rotation * collider.center) + transform.position - core.transform.position);
            }
            else
            {
                localPos = transform.position - core.transform.position;
            }
        }

        /*if (state == FlapperState.gaseous) {
         *      rigidbody.drag = JellyCore.gaseousDrag;
         * } else {
         *      rigidbody.drag = JellyCore.drag;
         * }*/
    }
 private void Start()
 {
     collidingWithSolid = false;
     flapper            = GameObject.Find("CORE").GetComponent <Transform>();
     state                = GameObject.Find("Flapper model").GetComponent <JellyBone>().state;
     particles            = GetComponentsInChildren <ParticleSystem>();
     robot                = gameObject.transform;
     currentRotationScale = rotationScale;
     currentSpeed         = speed;
     currPos              = robot.position;
     ManageRobotPosition();
 }
Example #4
0
    public void SetState(FlapperState newState)
    {
        switch (newState)
        {
        case FlapperState.gaseous:
            //gasParticleRenderer.material.SetColor("_BaseColor", gas);
            //gasParticleRenderer.material.SetColor("_EmissionColor", gas);
            gasParticle.startColor = gas;
            if (pm.moveType == MoveType.Rigidbody)
            {
                pm.velocity = gaseousSpeedRigidbody;
            }
            else if (pm.moveType == MoveType.Accelerate)
            {
                pm.velocity = gaseousAccelerate;
            }
            else
            {
                pm.speed = gaseousSpeed;
            }
            break;

        case FlapperState.jelly:
            meshRenderer.material.SetColor("_BaseColor", jelly);
            meshRenderer.material.SetColor("_EmissionColor", jelly);
            if (pm.moveType == MoveType.Rigidbody)
            {
                pm.velocity = jellySpeedRigidbody;
            }
            else if (pm.moveType == MoveType.Accelerate)
            {
                pm.velocity = jellyAccelerate;
            }
            else
            {
                pm.speed = jellySpeed;
            }
            break;

        case FlapperState.solid:
            meshRenderer.material.SetColor("_BaseColor", solid);
            meshRenderer.material.SetColor("_EmissionColor", solid);
            if (pm.moveType == MoveType.Rigidbody)
            {
                pm.velocity = solidSpeedRigidbody;
            }
            else if (pm.moveType == MoveType.Accelerate)
            {
                pm.velocity = solidAccelerate;
            }
            else
            {
                pm.speed = solidSpeed;
            }
            break;
        }
        if (newState == state)
        {
            return;
        }
        Debug.Log("New state: " + newState);
        state = newState;
        foreach (JellyBone b in bones)
        {
            b.SetState(state);
        }
        if (state == FlapperState.gaseous)
        {
            rigidbody.AddForce(Vector3.up * gaseousPush, ForceMode.Impulse);

            /*foreach (JellyBone bone in bones) {
             *      bone.GetComponent<Rigidbody>().AddForce(Vector3.up * gaseousPush, ForceMode.Impulse);
             * }*/
            //mesh.SetActive(false);

            /*foreach (GameObject go in gasParticles) {
             *      go.SetActive(true);
             * }*/
            //shadow.SetActive(false);
            gasParticle.Play();
            meshRenderer.enabled = false;
            audioSource.PlayOneShot(gasTransition);
        }
        else
        {
            //rigidbody.mass = defaultMass;
            //mesh.SetActive(true);

            /*foreach (GameObject go in gasParticles) {
             *      go.SetActive(false);
             * }*/
            //shadow.SetActive(true);
            gasParticle.Stop();
            meshRenderer.enabled = true;
            if (state == FlapperState.solid)
            {
                audioSource.PlayOneShot(solidTransition);
            }
            else
            {
                audioSource.PlayOneShot(jellyTransition);
            }
        }
        rigidbody.useGravity = state != FlapperState.gaseous;
        collider.enabled     = (state != FlapperState.solid);
    }