コード例 #1
0
    //update the hunger amount for the player
    public void UpdateHunger(float hungerAmt)
    {
        if (hitPoints < 1.0f)         //Don't add hunger if player is dead
        {
            return;
        }

        //Update hunger GUIText
        HungerText HungerText = hungerGuiObjInstance.GetComponent <HungerText>();

        HungerText[] HungerText2 = hungerGuiObjInstance.GetComponentsInChildren <HungerText>();

        //Apply hungerAmt
        if (hungerPoints + hungerAmt > maxHungerPoints)
        {
            hungerPoints = maxHungerPoints;
        }
        else
        {
            hungerPoints += hungerAmt;
        }

        //set hunger hud value to hunger points remaining
        HungerText.hungerGui     = Mathf.Round(hungerPoints);
        HungerText2[1].hungerGui = Mathf.Round(hungerPoints);

        //change color of hud hunger element based on hunger points
        if (hungerPoints <= 65.0f)
        {
            HungerText.GetComponent <GUIText>().material.color = HungerText.textColor;
        }
        else if (hungerPoints <= 85.0f)
        {
            HungerText.GetComponent <GUIText>().material.color = Color.yellow;
        }
        else
        {
            HungerText.GetComponent <GUIText>().material.color = Color.red;
        }

        lastHungerTime = Time.time;
    }
コード例 #2
0
    void Start()
    {
        mainCamTransform = Camera.main.transform;
        //Set time settings
        Time.timeScale = 1.0f;

        //Physics Layer Management Setup
        //these are the layer numbers and their corresponding uses/names accessed by the FPS prefab
        //	Weapon = 8;
        //	Ragdoll = 9;
        //	WorldCollision = 10;
        //	Player = 11;
        //	Objects = 12;
        //	NPCs = 13;
        //	GUICameraLayer = 14;
        //	WorldGeometry = 15;
        //	BulletMarks = 16;

        //player object collisions
        Physics.IgnoreLayerCollision(11, 12);       //no collisions between player object and misc objects like bullet casings
        Physics.IgnoreLayerCollision(12, 12);       //no collisions between bullet shells
        Physics.IgnoreLayerCollision(11, 9);        //no collisions between player and ragdolls
        Physics.IgnoreLayerCollision(9, 13);        //no collisions between ragdolls and NPCs

        //weapon object collisions
        Physics.IgnoreLayerCollision(8, 2);        //
        Physics.IgnoreLayerCollision(8, 13);       //no collisions between weapon and NPCs
        Physics.IgnoreLayerCollision(8, 12);       //no collisions between weapon and Objects
        Physics.IgnoreLayerCollision(8, 11);       //no collisions between weapon and Player
        Physics.IgnoreLayerCollision(8, 10);       //no collisions between weapon and world collision
        Physics.IgnoreLayerCollision(8, 9);        //no collisions between weapon and ragdolls

        //Call FadeAndLoadLevel fucntion with fadeIn argument set to true to tell the function to fade in (not fade out and (re)load level)
        GameObject llf = Instantiate(levelLoadFadeObj) as GameObject;

        llf.GetComponent <LevelLoadFade>().FadeAndLoadLevel(Color.black, 2.0f, true);

        //create Instance of GUIText to display health amount on hud
        healthGuiObjInstance = Instantiate(healthGuiObj, Vector3.zero, transform.rotation) as GameObject;
        //create Instance of GUIText to display help text
        helpGuiObjInstance = Instantiate(helpGuiObj, Vector3.zero, transform.rotation) as GameObject;
        //create Instance of GUITexture to display crosshair on hud
        CrosshairGuiObjInstance = Instantiate(CrosshairGuiObj, new Vector3(0.5f, 0.5f, 0.0f), transform.rotation) as GameObject;
        CrosshairGuiObjInstance.GetComponent <GUITexture>().texture = aimingReticle;
        //set alpha of hand pickup crosshair
        pickupReticleColor.a = 0.5f;
        //set alpha of aiming reticule and make it 100% transparent if crosshair is disabled
        if (crosshairEnabled)
        {
            reticleColor.a = 0.25f;
        }
        else
        {
            //make alpha of aiming reticle zero/transparent
            reticleColor.a = 0.0f;
            //set alpha of aiming reticle at start to prevent it from showing, but allow item pickup hand reticle
            CrosshairGuiObjInstance.GetComponent <GUITexture>().color = reticleColor;
        }

        //set reference for main color element of heath GUIText
        HealthText HealthText = healthGuiObjInstance.GetComponent <HealthText>();

        //set reference for shadow background color element of health GUIText
        //this object is a child of the main health GUIText object, so access it as an array
        HealthText[] HealthText2 = healthGuiObjInstance.GetComponentsInChildren <HealthText>();

        //initialize health amounts on GUIText objects
        HealthText.healthGui     = hitPoints;
        HealthText2[1].healthGui = hitPoints;

        if (usePlayerHunger)
        {
            //create Instance of GUIText to display hunger amount on hud
            hungerGuiObjInstance = Instantiate(hungerGuiObj, Vector3.zero, transform.rotation) as GameObject;
            //set reference for main color element of hunger GUIText
            HungerText HungerText = hungerGuiObjInstance.GetComponent <HungerText>();
            //set reference for shadow background color element of hunger GUIText
            //this object is a child of the main hunger GUIText object, so access it as an array
            HungerText[] HungerText2 = hungerGuiObjInstance.GetComponentsInChildren <HungerText>();

            //initialize hunger amounts on GUIText objects
            HungerText.hungerGui     = hungerPoints;
            HungerText2[1].hungerGui = hungerPoints;
        }

        if (usePlayerThirst)
        {
            //create Instance of GUIText to display thirst amount on hud
            thirstGuiObjInstance = Instantiate(thirstGuiObj, Vector3.zero, transform.rotation) as GameObject;
            //set reference for main color element of thirst GUIText
            ThirstText ThirstText = thirstGuiObjInstance.GetComponent <ThirstText>();
            //set reference for shadow background color element of thirst GUIText
            //this object is a child of the main thirst GUIText object, so access it as an array
            ThirstText[] ThirstText2 = thirstGuiObjInstance.GetComponentsInChildren <ThirstText>();

            //initialize thirst amounts on GUIText objects
            ThirstText.thirstGui     = thirstPoints;
            ThirstText2[1].thirstGui = thirstPoints;
        }
    }