示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (Uploading)
        {
            // While uploading (pathing towards the core) check if within the core.
            if (transform.position.x < 10 && transform.position.x > -10 && transform.position.y < 10 && transform.position.y > -10)
            {
                if (State != DataState.BLOCKED)
                {
                    scrAICore.Instance.Learn(State == DataState.INFECTED);
                }

                scrNodeMaster.Instance.DeactivateCube(Cube);
                Uploading = false;
                return;
            }

            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.identity, Time.deltaTime * 100);
        }

        if (State == DataState.INFECTED && !infectionTransitionCompleted)
        {
            infectionTransitionTimer += Time.deltaTime;
            if (infectionTransitionTimer >= infectionTransitionDuration)
            {
                infectionTransitionCompleted = true;
                renderer.material            = scrNodeMaster.Instance.MatCubeInfected;
            }
            else
            {
                // Interpolate between the colours of the materials with a unique material.
                float transition = infectionTransitionTimer / infectionTransitionDuration;
                renderer.material.SetColor("_GlowColor", Color.Lerp(StatePrev == DataState.BLOCKED ? scrNodeMaster.ColCubeBlocked : scrNodeMaster.ColCubeUninfected, scrNodeMaster.ColCubeInfected, transition));
            }
        }

        if (damageTimer >= damageToDestroy)
        {
            if (Parent == null)
            {
                GameObject explosion = (GameObject)Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
                explosion.particleSystem.startColor = Color.Lerp(renderer.material.GetColor("_GlowColor"), Color.white, 0.5f);

                scrNodeMaster.Instance.DeactivateCube(Cube);
            }
            else
            {
                if (Parent.VisibleToPlayer)
                {
                    GameObject explosion = (GameObject)Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
                    explosion.particleSystem.startColor = Color.Lerp(renderer.material.GetColor("_GlowColor"), Color.white, 0.5f);
                }

                Parent.RemoveCube(Cube);
            }
        }
        else
        {
            if (damageTimer < 0)
            {
                damageTimer = 0;

                switch (State)
                {
                case DataState.BLOCKED:
                    renderer.material = scrNodeMaster.Instance.MatCubeBlocked;
                    break;

                case DataState.CLEAN:
                    renderer.material = scrNodeMaster.Instance.MatCubeUninfected;
                    break;

                case DataState.INFECTED:
                    renderer.material = scrNodeMaster.Instance.MatCubeInfected;
                    break;
                }
            }
            else if (damageTimer > 0)
            {
                damageTimer            -= 2 * Time.deltaTime;
                renderer.material.color = Color.Lerp(Color.black, Color.white, damageTimer / damageToDestroy);
            }
        }
    }