Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        //audio = GetComponent<AudioSource> ();
        meshes    = new GameObject[4][];
        meshes[0] = fireMeshes;
        meshes[1] = earthMeshes;
        meshes[2] = magnetMeshes;
        meshes[3] = lightningMeshes;

        rb = GetComponent <Rigidbody>();

        ChangeMovementState(State.GroundedMovement);

        holding = false;

        // Change this to be added by menu system!!
        int output;

        int.TryParse(PlayerNumber, out output);
        if (GameManager.Inst.PlayerSkills.Count > output && Skill == SkillID.None)
        {
            Skill = GameManager.Inst.PlayerSkills[output];
        }
        else if (Skill == SkillID.None)
        {
            Skill = SkillID.Meteor;
        }

        if (Skill == SkillID.Meteor)
        {
            playerSkill = gameObject.AddComponent <MeteorAbility>();

            fireMeshIndices    = new bool[2][];
            fireMeshIndices[0] = new bool[8] {
                true, false, false, false, false, true, true, false
            };
            fireMeshIndices[1] = new bool[3] {
                false, false, true
            };
        }
        //else if (Skill == SkillID.IceWall)
        //{
        //    playerSkill = gameObject.AddComponent<IceWallAbility>();
        //}
        else if (Skill == SkillID.MagneticBlast)
        {
            playerSkill = gameObject.AddComponent <MagneticBlastAbility>();
        }
        else if (Skill == SkillID.Earth)
        {
            playerSkill = gameObject.AddComponent <EarthAbility>();
        }
        else if (Skill == SkillID.Lightning)
        {
            playerSkill = gameObject.AddComponent <LightningAbility>();

            lightningMeshIndices = new bool[2][];

            lightningMeshIndices[0] = new bool[4] {
                false, false, true, true
            };
            lightningMeshIndices[1] = new bool[1] {
                true
            };
        }
        else if (Skill == SkillID.None)
        {
            playerSkill = gameObject.AddComponent <MeteorAbility>();
        }

        if (models[(int)Skill] != null)
        {
            switch (Skill)
            {
            case SkillID.Earth:
                for (int i = 0; i < meshes[(int)Skill].Length; ++i)
                {
                    for (int j = 0; j < meshes[(int)Skill][i].GetComponent <Renderer>().materials.Length; ++j)
                    {
                        MaterialPropertyBlock prop = new MaterialPropertyBlock();
                        prop.SetColor("_Color", color.color);
                        meshes[(int)Skill][i].GetComponent <Renderer>().SetPropertyBlock(prop);
                    }
                }
                break;

            case SkillID.Meteor:
                for (int i = 0; i < meshes[(int)Skill].Length; ++i)
                {
                    for (int j = 0; j < meshes[(int)Skill][i].GetComponent <Renderer>().materials.Length; ++j)
                    {
                        if (fireMeshIndices[i][j] == true)
                        {
                            MaterialPropertyBlock prop = new MaterialPropertyBlock();
                            prop.SetColor("_Color", color.color);
                            meshes[(int)Skill][i].GetComponent <Renderer>().materials[j].SetColor("_Color", color.color);

                            if (i == 1)
                            {
                                meshes[(int)Skill][i].GetComponent <Renderer>().materials[j].color *= 0.4f;
                            }
                        }
                    }
                }
                break;

            case SkillID.MagneticBlast:
                for (int i = 0; i < meshes[(int)Skill].Length; ++i)
                {
                    MaterialPropertyBlock prop = new MaterialPropertyBlock();
                    prop.SetColor("_Color", color.color);
                    meshes[(int)Skill][i].GetComponent <Renderer>().SetPropertyBlock(prop);
                }
                break;

            case SkillID.Lightning:
                for (int i = 0; i < meshes[(int)Skill].Length; ++i)
                {
                    for (int j = 0; j < meshes[(int)Skill][i].GetComponent <Renderer>().materials.Length; ++j)
                    {
                        if (lightningMeshIndices[i][j] == true)
                        {
                            MaterialPropertyBlock prop = new MaterialPropertyBlock();
                            prop.SetColor("_Color", color.color);
                            meshes[(int)Skill][i].GetComponent <Renderer>().materials[j].SetColor("_Color", color.color);

                            if (i == 0 && j == 3)
                            {
                                meshes[(int)Skill][i].GetComponent <Renderer>().materials[j].color *= 0.4f;
                            }
                        }
                    }
                }
                break;
            }
            wizardModel.gameObject.SetActive(false);
            wizardModel = models[(int)Skill].transform;
            wizardModel.gameObject.SetActive(true);
            modelAnimator = wizardModel.GetComponent <Animator>();
        }


        if (Skill != SkillID.None)
        {
            cdtext.sprite = GameManager.Inst.CDIndicators[(int)Skill];
        }
        else
        {
            cdtext.sprite = GameManager.Inst.CDIndicators[(int)SkillID.Meteor];
        }

        // Change this to be added by menu system!!

        playerSkill.Initialize(color, indicatorColor, PlayerNumber, gameObject, missileSpawnLocation);

        // Warp Particles
        if (Skill != SkillID.None)
        {
            Instantiate(warpParticles, gameObject.transform.localPosition, Quaternion.identity);
        }

        willFire = false;

        float grabTime = 0.0f;

        GameManager.Inst.AddPlayer(this.GetComponent <PlayerController>());

        dead = false;

        cdtext.enabled = false;

        currentMaxSpeed = maxSpeed;

        IceBrake.GetComponent <Renderer>().enabled = false;

        tempedamage       = environmentDamage;
        environmentDamage = 0;
        Countdown(startTime);

        cdtext.type       = Image.Type.Filled;
        cdtext.fillMethod = Image.FillMethod.Radial360;
    }