// Use this for initialization void Start() { if (!healthTextGameObject) { healthTextGameObject = GameObject.FindObjectOfType <HealthText> (); } }
// Start is called before the first frame update void Start() { healthBarTransform = gameObject.transform.Find("HealthBar"); healthBarPositionVector = healthBarTransform.localPosition; healthBarScaleVector = healthBarTransform.localScale; maxScaleX = healthBarTransform.localScale.x; healthText = gameObject.transform.Find("HpTextCanvas/HpText").GetComponent <HealthText>(); }
protected override void Awake() { anim = GetComponent <Animator>(); healthText = GameObject.Find("Lives Text").GetComponent <HealthText>(); base.Awake(); health = startHealth; healthbar.localScale = new Vector3(health * startScale / startHealth, 1, 1); }
protected override void Awake() { anim = GetComponent<Animator>(); healthText = GameObject.Find("Lives Text").GetComponent<HealthText>(); base.Awake(); health = startHealth; healthbar.localScale = new Vector3(health * startScale / startHealth, 1, 1); }
// Start is called before the first frame update void Start() { myRigidbody2d = GetComponent <Rigidbody2D>(); myAnimator = GetComponent <Animator>(); myhealthText = FindObjectOfType <HealthText>(); if (myhealthText) { myhealthText.SetHealthText(PlayerHealth); } StartingSpeed = PlayerSpeed; }
// Use this for initialization void Start() { enemiesKilled = 0; npcRegistry = GameObject.FindObjectOfType <NPCRegistry> (); healthText = GameObject.FindObjectOfType <HealthText> (); //hudMenu = GameObject.FindObjectOfType<HudMenuController> (); abComplete = 0; abFail = 0; totalEnemies = GameObject.FindObjectsOfType <AI> ().Length; }
//Called in the update method; assigns player UI elements to their correct values void UpdatePlayerStats() { HealthText.SetText(this.HP.ToString()); TavernHealthText.SetText(this.HP.ToString()); TavernGoldText.SetText(gold.ToString()); GoldText.SetText(gold.ToString()); XPText.SetText(xp.ToString()); LevelText.SetText(level.ToString()); TurnsText.SetText(turnNumber.ToString()); }
private void GatherResources() { int resource = (int)TowerDamage(type, stats) + stats[1] * 10; GameStats.EcResources += resource; GameStats.totalResourcesGathered += resource; if (healthText == null || healthText.p > 0.7f) { healthText = new HealthText("$" + resource, 1) { Position = GlobalPosition + new Vector2(0, -15) }; healthText.startColor = Color.Yellow; healthText.endColor = Color.Yellow; MyPlane.Add(healthText); } }
// Start is called before the first frame update void Start() { rigidbody = GetComponent <Rigidbody2D>(); spriteRenderer = GetComponent <SpriteRenderer>(); gameController = FindObjectOfType <GameController>(); cameraPos = Camera.main.transform.position; transform.position = spawnLocation - new Vector3(2, 0, 0); leftEdgeCollider = GameObject.FindGameObjectWithTag("LeftEdgeCollider"); healthText = FindObjectOfType <HealthText>(); pickupParticles = gameObject.transform.Find("Pickup Particles").GetComponent <ParticleSystem>(); leftEdgeCollider.SetActive(false); rigidbody.velocity = new Vector3(speed / 5, 0, 0); GetComponent <FadeObject>().TriggerFadeIn(); currentHealth = startingHealth; healthText.UpdateHealthDisplay(currentHealth); }
// Update is called once per frame void Update() { if (!healthTextGameObject) { healthTextGameObject = GameObject.FindObjectOfType <HealthText> (); } if (healthTextGameObject) { healthTotal = (int)healthTextGameObject.healthGui; healthValueForBar = (float)healthTotal / 100.0f; float newValue = Mathf.Clamp(healthValueForBar, 0f, 1f); HealthImageObj.fillAmount = newValue; if (healthTotal < 0) { healthTotal = 0; } healthTextObj.text = "" + healthTotal + "%"; } }
//add hitpoints to player health public void HealPlayer(float healAmt) { if (hitPoints < 1.0f) //Don't add health if player is dead { return; } //Update health GUIText HealthText HealthText = healthGuiObjInstance.GetComponent <HealthText>(); HealthText[] HealthText2 = healthGuiObjInstance.GetComponentsInChildren <HealthText>(); //Apply healing if (hitPoints + healAmt > maximumHitPoints) { hitPoints = maximumHitPoints; } else { hitPoints += healAmt; } //set health hud value to hitpoints remaining HealthText.healthGui = Mathf.Round(hitPoints); HealthText2[1].healthGui = Mathf.Round(hitPoints); //change color of hud health element based on hitpoints remaining if (hitPoints <= 25.0f) { HealthText.guiText.material.color = Color.red; } else if (hitPoints <= 40.0f) { HealthText.guiText.material.color = Color.yellow; } else { HealthText.guiText.material.color = HealthText.textColor; } }
public void DrawHealth() { //HideHudAndRadarThisFrame(); HideReticle(); HealthText.Caption = Game.Player.Character.Health.ToString(); AmmoText.Caption = Game.PlayerPed.Weapons.Current.AmmoInClip.ToString() + " + " + latestAmmo; if (Game.PlayerPed.IsReloading) { latestAmmo = Game.PlayerPed.Weapons.Current.Ammo - Game.PlayerPed.Weapons.Current.AmmoInClip; } DrawRectangle(0.025f, 0.9038f, 0.12f, 0.035f, 0, 0, 0, 200); float healthPercent = (float)Game.Player.Character.Health / Game.Player.Character.MaxHealth; if (healthPercent < 0) { healthPercent = 0; } if (healthPercent > 1) { healthPercent = 1; } DrawRectangle(0.025f, 0.9038f, healthPercent * 0.12f, 0.035f, 200, 46, 48, 255); DrawRectangle(0.025f, 0.9038f, 0.007f, 0.035f, 150, 1, 3, 255); float ammoPercent = (float)Game.PlayerPed.Weapons.Current.AmmoInClip / Game.PlayerPed.Weapons.Current.MaxAmmoInClip; DrawRectangle(0.025f, 0.94f, 0.12f, 0.03f, 0, 0, 0, 200); DrawRectangle(0.025f, 0.94f, ammoPercent * 0.12f, 0.03f, 206, 155, 1, 200); DrawRectangle(0.025f, 0.94f, 0.007f, 0.03f, 160, 106, 0, 255); HealthText.Draw(); AmmoText.Draw(); }
//remove hitpoints from player health public void ApplyDamage(float damage) { FPSRigidBodyWalker FPSWalkerComponent = GetComponent <FPSRigidBodyWalker>(); float appliedPainKickAmt; if (hitPoints < 1.0f) //Don't apply damage if player is dead { return; } //Update health GUIText HealthText HealthText = healthGuiObjInstance.GetComponent <HealthText>(); HealthText[] HealthText2 = healthGuiObjInstance.GetComponentsInChildren <HealthText>(); Quaternion painKickRotation; //Set up rotation for pain view kicks int painKickUpAmt = 0; int painKickSideAmt = 0; hitPoints -= damage; //Apply damage //set health hud value to hitpoints remaining HealthText.healthGui = Mathf.Round(hitPoints); HealthText2[1].healthGui = Mathf.Round(hitPoints); //change color of hud health element based on hitpoints remaining if (hitPoints <= 25.0f) { HealthText.guiText.material.color = Color.red; } else if (hitPoints <= 40.0f) { HealthText.guiText.material.color = Color.yellow; } else { HealthText.guiText.material.color = HealthText.textColor; } GameObject pf = Instantiate(painFadeObj) as GameObject; //Create instance of painFadeObj pf.GetComponent <PainFade>().FadeIn(PainColor, 0.75f); //Call FadeIn function in painFadeObj to fade screen red when damage taken if (!FPSWalkerComponent.holdingBreath) { //Play pain sound when getting hit if (Time.time > gotHitTimer && painBig && painLittle) { // Play a big pain sound if (hitPoints < 40 || damage > 30) { AudioSource.PlayClipAtPoint(painBig, mainCamTransform.position); gotHitTimer = Time.time + Random.Range(.5f, .75f); } else { //Play a small pain sound AudioSource.PlayClipAtPoint(painLittle, mainCamTransform.position); gotHitTimer = Time.time + Random.Range(.5f, .75f); } } } else { if (Time.time > gotHitTimer && painDrown) { //Play a small pain sound AudioSource.PlayClipAtPoint(painDrown, mainCamTransform.position); gotHitTimer = Time.time + Random.Range(.5f, .75f); } } painKickUpAmt = Random.Range(100, -100); //Choose a random view kick up amount if (painKickUpAmt < 50 && painKickUpAmt > 0) { painKickUpAmt = 50; } //Maintain some randomness of the values, but don't make it too small if (painKickUpAmt < 0 && painKickUpAmt > -50) { painKickUpAmt = -50; } painKickSideAmt = Random.Range(100, -100); //Choose a random view kick side amount if (painKickSideAmt < 50 && painKickSideAmt > 0) { painKickSideAmt = 50; } if (painKickSideAmt < 0 && painKickSideAmt > -50) { painKickSideAmt = -50; } //create a rotation quaternion with random pain kick values painKickRotation = Quaternion.Euler(mainCamTransform.localRotation.eulerAngles - new Vector3(painKickUpAmt, painKickSideAmt, 0)); //make screen kick amount based on the damage amount recieved if (zoomed) { appliedPainKickAmt = (damage / (painScreenKickAmt * 10)) / 3; } else { appliedPainKickAmt = (damage / (painScreenKickAmt * 10)); } //make sure screen kick is not so large that view rotates past arm models appliedPainKickAmt = Mathf.Clamp(appliedPainKickAmt, 0.0f, 0.15f); //smooth current camera angles to pain kick angles using Slerp mainCamTransform.localRotation = Quaternion.Slerp(mainCamTransform.localRotation, painKickRotation, appliedPainKickAmt); //Call Die function if player's hitpoints have been depleted if (hitPoints < 1.0f) { Die(); } }
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, 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; //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 heath 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; }
// Use this for initialization void Start() { m_Rigidbody = GetComponent<Rigidbody>(); //Attach a health indicator to this player; m_PlayerUICanvas = GameObject.FindGameObjectWithTag(ConstParams.PlayerUICanvasTag).transform; m_HealthText = (Instantiate(Resources.Load(ConstParams.HealthTextObject), new Vector3(Screen.width / 8, Screen.height / 8, 0), Quaternion.identity) as GameObject).GetComponent<HealthText>(); m_HealthText.transform.SetParent(m_PlayerUICanvas); m_HealthText.Player = gameObject; //Get the player's ID PlayerID = GameObject.FindObjectsOfType<HealthText>().Length; //Change texture to fit player ID GetComponent<Renderer>().material.mainTexture = m_PlayerTextures[PlayerID - 1]; Random.seed = System.DateTime.Now.Millisecond; }
private void Awake() { dealDamage = FindObjectOfType <HealthText>(); }