Example #1
0
    // Use this for initialization
    void Start()
    {
        // load information from saved data, which is updated whenever a new character is bought
        for (int i = 0; i < numChars; i++)
        {
            CharInfo c = models[i].GetComponent <CharInfo>();
            if (c != null)
            {
                c.Purchased = GameSaver.gSaver.charBought[i];
                c.level     = GameSaver.gSaver.charLevel[i];
            }
        }


        cam   = Camera.main;
        plane = new Plane(Vector3.up, player.transform.position);         //creates a plane at the players base for player rotation

        //init the distance halo... not really for dragon warning
        HaloScript dScript = dragWarn.GetComponent <HaloScript>();

        if (dScript == null)
        {
            Debug.Log("InitPlayer() couldnt get a reference to the halo script for dragon warning");
        }
        else
        {
            dScript.InitHalo(1);
            dragWarn.SetActive(false);
        }

        // init the arrows
        HaloScript laScript = lArr.GetComponent <HaloScript>();

        if (laScript == null)
        {
            Debug.Log("InitPlayer() couldnt get a reference to the halo script for left arrow");
        }
        else
        {
            laScript.InitHalo(1);
            lArr.SetActive(false);
        }

        HaloScript raScript = rArr.GetComponent <HaloScript>();

        if (raScript == null)
        {
            Debug.Log("InitPlayer() couldnt get a reference to the halo script for right arrow");
        }
        else
        {
            raScript.InitHalo(1);
            rArr.SetActive(false);
        }
    }
Example #2
0
    public void InitPlayer(int index)
    {
        //adjust the Character Controller to fit the Box Collider that SHOULD be included with the suriyan models
        box = player.GetComponent <BoxCollider>();
        Vector3 vec  = new Vector3(1, 1, 1);
        Vector3 vec2 = new Vector3(1, 1, 1);

        if (box == null)
        {
            Debug.Log("Could not Get Box Collider component.");
        }
        else
        {
            vec  = box.size;
            vec2 = box.center;
        }
        charControl = player.AddComponent <CharacterController> () as CharacterController;
        if (charControl != null)
        {
            charControl.radius = (vec.x + vec.y + vec.z) * 0.33f * 0.33f;             // average all three box collider dimensions, then take a third of that
            charControl.center = new Vector3(0, (vec2.y), 0);
            charControl.height = vec2.y + 0.3f;
            //set the y value for when player block comes back up
            yStandCapture = box.center.y;
            yStandLatch   = false;
        }

        anim   = player.GetComponent <Animator>();
        animId = Animator.StringToHash("animation");

        moveDirClamp  = player.transform.position;
        lookDirClamp  = player.transform.position;
        moveDirection = Vector3.zero;
        jumpCtr       = 0;   // may be redundant. im paranoid at this point
        jumpDist      = 0.0f;
        //setPlaneOnce = true;
        landOnce           = true;
        player.tag         = "Player";
        jumpAmp            = 2.0f;
        playerStuckOnce    = false;
        playerDieSoundOnce = false;

        //character info stuff
        CharInfo c = player.GetComponentInChildren <CharInfo>();

        if (c == null)
        {
            Debug.Log("No Character Info found");
        }

        cName           = c.Name;
        scaleFactor     = c.ScaleFactor;
        colorA          = c.colorA;
        colorB          = c.colorB;
        DoAvatarScaling = c.DoAvatarScaling;
        musicLoop       = c.MusicLoop;
        maxDistance     = c.Distance;
        jumpTimes       = c.JumpTimes;
        frozen          = c.worldBottomColor;
        c.level         = GameSaver.gSaver.charLevel[index];
        charLevel       = c.level;

        //calculate end level coin counter
        endLevelCoinCounter  = 0;
        maxEndRoundCoinCount = 3 * 5 * charLevel;

        skyBox = GameObject.FindGameObjectWithTag("SkyBoxController").GetComponent <SkyboxController>();
        if (skyBox == null)
        {
            Debug.Log("Player Controller couldnt get a reference to the skybox controller.");
        }
        else
        {
            skyBox.TopColor    = c.worldTopColor;
            skyBox.BottomColor = c.worldBottomColor;
        }



        //init the distance halo. Need to call InitHalo() below the character info
        HaloScript hScript = halo.GetComponent <HaloScript>();

        if (hScript == null)
        {
            Debug.Log("InitPlayer() couldnt get a reference to the halo script");
        }
        else
        {
            hScript.InitHalo(maxDistance);
            halo.SetActive(true);
        }



        //update the jump x side bar ui text
        Text jumpX = GameObject.FindGameObjectWithTag("uiJumpTimes").GetComponent <Text>();

        if (jumpX != null)
        {
            string str = "Jump X" + jumpTimes.ToString();
            jumpX.text = str;
        }

        //god im not proud of this. shitty design work
        //update the sprite for the progress bar
        Image           bar = GameObject.FindGameObjectWithTag("uiProgressIndicator").GetComponent <Image>();
        MenuButton      foo = GameObject.FindGameObjectWithTag("MenuButton").GetComponent <MenuButton>();
        CharacterButton b;

        GameObject[] butts = GameObject.FindGameObjectsWithTag("uiCharButton");
        if (butts != null)
        {
            foreach (GameObject g in butts)
            {
                b = g.GetComponent <CharacterButton>();
                if (b != null)
                {
                    if (b.charIndex == gScript.GetPlayerIndex())
                    {
                        if (bar != null)
                        {
                            bar.sprite = b.GetSprite();
                        }
                        if (foo != null)
                        {
                            foo.SetCharSelected(gScript.GetPlayerIndex(), b.GetSprite());
                        }
                    }
                }
            }
        }

        SetCharacterName(cName);
        //SetNumLivesUI();
    }