Post by jgiroux on Jul 20, 2016 20:02:23 GMT
XP LEVELING/SURVIVAL ADDON
as promised here is the code. should work out of box in next update but for versions below "c" you will need to make one small edit
//open your vCharacter.cs script from Invector3rdPersonController->Scripts->CharacterController folder.
once open navigate to
#region Character Variables
within there
change
protected float currentStamina to public float currentStamina.
compile.
Now create the two following scripts. remember to do the above step First before creating the following scripts otherwise you will get errors upon compiling since the stamina in Invectors code may be a protected variable depending on version you own.
create a new c# script and call it - InvectorAddOn -
open it and erase everything inside then copy/paste code and save/build
using UnityEngine;
using Invector.CharacterController;
using Invector;
using System.Text;
using System;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Collections;
public class InvectorAddOn : MonoBehaviour
{
#region Invector Bridge
[System.Serializable]
public class Vinvectorbridge
{
[Tooltip("Drag Player with Invector V3rdPersonController Component to here")]
public vThirdPersonController myController;
[Tooltip("Drag Prefab 'audiosource' from Assets->Invector-3rd personController->scripts->Footstep->audiosource folder to here")]
public GameObject audioSource;
[Header("--OPTIONAL OVERRIDES ___________________________")]
// added 7/30 josh edit // add new blood splash screen on damage and health/stamina UI options
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max HUD, remember to disable the original Invector health under GUI panel, leave empty if you do not wish to use")]
public Image UI_HealthFillImage;
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max HUD, remember to disable the original Invector health under GUI panel, leave empty if you do not wish to use")]
public Image UI_StaminaFillImage;
[Tooltip("This allows more than one Damage Splash screen to be displayed randomly on each damage screen flash, These will replace any image you already have set for your Invector UIHud controller damage image. leave empty if you do not wish to use")]
public Image[] DamageSplashScreens;
// end edit 7/30
}
[Header("______ INVECTOR BRIDGE ___________________________")]
public Vinvectorbridge InvectorBridge;
#endregion
#region Invector Stats
[System.Serializable]
public class VinvectorbridgeStats
{
[Tooltip("Invector current health from Invector 3rdPerson Component")]
public float Vcurrent_health; // get health from inector 3rdperson controller
[Tooltip("Invector current stamina from Invector 3rdPerson Component")]
public float Vcurrent_stamina; // get stamina from invector 3rdperson controller
[Tooltip("Invector current max health from Invector 3rdPerson Component")]
public float VMaxhealth; // get max health from invector 3rdperson controller
[Tooltip("Invector current max stamina from Invector 3rdPerson Component")]
public float VMaxstamina; // get max stamina from invector 3rdperson controller
[System.Serializable]
public class VinvectorbridgeStatsHSR
{
[Tooltip("Invector current health recovery from Invector 3rdPerson Component")]
public float VhealthRecovery; // get health recovery from invector 3rdperson controller
[Tooltip("Invector current health recovery delay from Invector 3rdPerson Component")]
public float VhealthRecoveryDelay; // get health recovery delay from invector 3rdperson controller
[Tooltip("Invector current stamina recovery from Invector 3rdPerson Component")]
public float VstaminaRecovery; // get stamina recovery from invector 3rdperson controller
}
[Tooltip("Invector Recovery Stats")]
public VinvectorbridgeStatsHSR RecoveryStats;
}
[Header("______ INVECTOR STATS ___________________________")]
[Tooltip("Invector Stats, these will be populated at runtime from invector 3rdperson component")]
public VinvectorbridgeStats InvectorStats;
#endregion
#region Player Leveling
[System.Serializable]
public class PlayerLevelStats
{
[Space(10)]
[Tooltip("players current level")]
public int PlayersLevel; // current level of player
[Space(10)]
[Header("____________________PLAYER EXPERIENCE ________________________")]
[Tooltip("players current xp gain")]
public float PlayerCurrentXP; // current XP of player
[Tooltip("a running value of the total XP gained over history of players levels")]
public float PlayerLifetimeXP; // a running value of the total XP gained over history of players levels
[Tooltip("next amount of XP needed to gain a new level")]
public float current_xp_to_nxt_Level; // next amount of XP needed to gain a new level
[Tooltip("the maximum level a player can attain")]
public int m_maximumLevel = 100; // maximum level
[Header("____________________LEVEL PROGRESSION _________________________")]
/// The list of scores required to advance to the next level. these can be changed in the inspector
[Tooltip("Create a series of increasing XP for each level increase")]
public int[] m_nextLevelScore = { 0, 3000, 7000, 12000, 18000, 25000, 34000,
44000, 56000, 69000, 80000 };
/// The number of required points to score to advance to the next level once
//the score has gone beyond the provided list of points. this can be changed in Inspector
public int m_nextLevelScoreProgression = 100000;
[System.Serializable]
public class MyLevelUpFeatures
{
[Header("____________________LEVEL UP MULTIPLIER_________________")]
[Tooltip("a integer to multiply by players level to get new health bonus on level up")]
[Space(10)]
public int VHealthMultiplier;
[Tooltip("a integer to multiply by players level to get new stamina bonus on level up")]
public int VStaminaMultiplier;
[Space(10)]
[Header("____________________SOUND FX_______________________")]
[Tooltip("Play a sound on Level up, leave empty if you dont want a sound played")]
public AudioClip m_LevelUpSound;
[Space(10)]
[Tooltip("Play a VFX particle on Level up, leave empty if you dont want a VFX particle played")]
[Header("____________________PARTICLE VFX and POSITION___________________")]
public GameObject LevelUpVFX;
[Tooltip("the offset of the above VFX spawnpoint")]
public Vector3 LevelUpVFXOffset = new Vector3(0.5f, 0.5f, 0.5f);
}
[Tooltip("Here you can adjust several features of leveling up")]
public MyLevelUpFeatures LevelUpFeatures;
[System.Serializable]
public class UI_LevelElements
{
[Header("____________________UI SPLASH TEXT_______________________")]
[Tooltip("a UItext that will display on Level Up example:'you have gained a new level!!!', create a new UItext as assign here, leave blank if you do not want to use this feature")]
public Text UI_MyLevelUpSplashText;
[Tooltip("Time for splash text on level up to stay on screen before fade")]
public float SplashTexttime = 10; // change how log splash level up text is displayed on screen/ higher number = longer screen time.
[Header("____________________UI XP GAINED TEXT_______________________")]
[Tooltip("a UItext that will display on enemy death example:'you have gained 200XP', create a new UItext and assign here, leave blank if you do not want to use this feature")]
public Text UI_XPGainedSplashText;
[Tooltip("Time for XP gained splash text to stay on screen before fade")]
public float XPGainedSplashTextTime = 5; // change how log splash level up text is displayed on screen/ higher number = longer screen time.
[Header("____________________UI PLAYER CURRENT LEVEL TEXT_______________________")]
[Tooltip("a UItext that will display the players current level, create a new UItext and assign here, leave blank if you do not want to use this feature")]
public Text UI_MyLevelNumber;
[Header("____________________UI XP BAR FILL GRAPHIC_______________________")]
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max XP HUD")]
public Image UI_XPFillImage;
[Header("____________________UI CUSTOM IMAGE_______________________")]
[Tooltip("a UIImage that will fade in and out upon level up, create a new UIImage and assign here, leave blank if you do not want to use this feature")]
public Image levelUpScreenOverlay;
[Tooltip("How long will above UIImage take to fade in/fade out")]
public float levelUpScreenOverlayTime = 4f;
}
[Tooltip("Here you can adjust several UI features of leveling up")]
public UI_LevelElements LevelUpUIElements;
}
[Tooltip("Player level system and features")]
[Header("______ PLAYER LEVELING SYSTEM _____________________")]
public PlayerLevelStats PlayerLevel;
#endregion
#region Hunger Thirst System
[System.Serializable]
public class Hungerthirstsystem
{
#region hunger
[Header("--Hunger--")]
[Tooltip("enable hunger? yes is checked/ no is unchecked")]
public bool UseHunger;
public float CurrentHunger;
public float MaxHunger = 100;
[Tooltip("a integer to multiply by players level to get new health bonus on level up")]
public int HungerMultiplier = 15;
[Tooltip("a float value that determines how fast your hunger increases")]
public float HungerModifier = .1f;
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max HUD")]
public Image UI_HungerFillImage;
[Tooltip("a UIImage that will fade in and out at critical threshold")]
public Image UI_HungerScreenOverlay;
[Tooltip("How long will above UIImage take to fade in/fade out")]
public float UI_HungerScreenOverlayTime = 4f;
[Tooltip("Play a sound at critical threshold, leave empty if you dont want a sound played")]
public AudioClip HungerCriticalSound;
#endregion
#region thirst
[Header("--Thirst--")]
[Tooltip("enable thirst? yes is checked/ no is unchecked")]
public bool UseThirst;
public float CurrentThirst;
public float MaxThirst = 100;
[Tooltip("a integer to multiply by players level to get new health bonus on level up")]
public int ThirstMultiplier = 15;
[Tooltip("a float value that determines how fast your thirst increases")]
public float ThirstModifier = .3f;
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max HUD")]
public Image UI_ThirstFillImage;
[Tooltip("a UIImage that will fade in and out at critical levels")]
public Image UI_ThirstScreenOverlay;
[Tooltip("How long will above UIImage take to fade in/fade out")]
public float UI_ThirstScreenOverlayTime = 4f;
[Tooltip("Play a sound at critical threshold, leave empty if you dont want a sound played")]
public AudioClip ThirstCriticalSound;
#endregion
#region rest
[Header("--Rest--")]
[Tooltip("enable rest? yes is checked/ no is unchecked")]
public bool UseRest;
public float CurrentRest;
public float MaxRest = 100;
[Tooltip("a integer to multiply by players level to get new health bonus on level up")]
public int RestMultiplier = 15;
[Tooltip("a float value that determines how fast your rest/tiredness increases")]
public float RestModifier = .05f;
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max HUD")]
public Image UI_RestFillImage;
[Tooltip("a UIImage that will fade in and out at critical levels")]
public Image UI_RestScreenOverlay;
[Tooltip("How long will above UIImage take to fade in/fade out")]
public float UI_RestScreenOverlayTime = 4f;
[Tooltip("Play a sound at critical threshold, leave empty if you dont want a sound played")]
public AudioClip RestCriticalSound;
#endregion
#region bodytemp
[Header("--BodyTemp--")]
[Tooltip("enable body temperature? yes is checked/ no is unchecked")]
public bool UseBodyTemp;
public float CurrentBodyTemp = 98.5f;
public float MaxBodyTemp = 200.5f;
public float NormalBodyTemp = 98.5f;
[Tooltip("a integer to multiply by players level to get new health bonus on level up")]
public int BodyTempMutiplier;
[Tooltip("a float value that determines how fast your body temp increases/decreases")]
public float BodyTempModifier = .1f;
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max HUD")]
public Image UI_BodyTempFillImage;
[Tooltip("a bool to trigger body temp dropping/ includes options for custom fade in overlay texture - fade out overlay texture")]
public bool isGettingCold = false;
public bool isGettingHot = false;
[Tooltip("a UIImage that will fade in and out at critical levels")]
public Image UI_FrozenScreenOverlay;
[Tooltip("a UIImage that will fade in and out at critical levels")]
public Image UI_HeatedScreenOverlay;
[Tooltip("Play a sound at critical threshold, leave empty if you dont want a sound played")]
public AudioClip FrozenCriticalSound;
[Tooltip("Play a sound at critical threshold, leave empty if you dont want a sound played")]
public AudioClip HeatedCriticalSound;
#endregion
#region breath
[Header("--Breath--")]
[Tooltip("enable holding breath? yes is checked/ no is unchecked")]
public bool UseBreath;
public float CurrentBreath;
public float MaxBreath = 10;
[Tooltip("a integer to multiply by players level to get new health bonus on level up")]
public int BreathMutiplier = 15;
[Tooltip("a float value that determines how fast your lack of oxygen increases")]
public float BreathModifier = 1.5f;
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max HUD")]
public Image UI_BreathFillImage;
[Tooltip("a bool to trigger if player is holding breath, if ON holding breath values will increase to max / if OFF will decrease to zero")]
public bool isHoldingBreath = false;
[Tooltip("a UIImage that will fade in and out at critical levels")]
public Image UI_OutOfBreathOverlay;
[Tooltip("Play a sound at critical threshold, leave empty if you dont want a sound played")]
public AudioClip OutOfBreathCriticalSound;
#endregion
}
[Header("______ HUNGER/THIRST SYSTEM _____________________")]
[Tooltip("Here you can enable/disable and set certain features of a generic hunger/thirst system")]
public Hungerthirstsystem HungerThirstElements;
#endregion
#region Attribute System
[System.Serializable]
public class AttributePlayer
{
[Header("--STATS--")]
[Range(1, 25)]
public int Intelligence = 10;
[Range(1, 25)]
public int Strength = 10;
[Range(1, 25)]
public int Dexterity = 10;
[Range(1, 25)]
public int Spirit = 10;
public int Spellcasting; // tied to intelligence
public int SpellcastingMax;
[Range(1, 25)]
public int SpellcastingModifierOnLevelUp;
public int Rage; // tied to strength
public int RageMax; // tied to strength
[Range(1, 25)]
public int RageModifierOnLevelUp;
public int Swiftness; // tied to dexterity
public int SwiftnessMax;
[Range(1, 25)]
public int SwiftnessModifierOnLevelUp;
public int Healing;
public int HealingMax;
[Range(1, 25)]
public int HealingModifierOnLevelUp;
#region mana
[Header("--MANA--")]
[Tooltip("enable Mana use? checked = Yes, unchecked = NO")]
public bool UseMana;
public float CurrentMana;
public float MaxMana = 100;
[Tooltip("a integer to multiply by players level to get new health bonus on level up")]
public int ManaMultiplier = 15;
[Tooltip("a float value that determines how fast your mana increases")]
public float ManaRegenModifier = 5;
[Tooltip("a float value that determines how fast your mana decreases")]
public float ManaCastingModifier = 25f;
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max Mana HUD, leave blank if you do not want to use this feature")]
public Image UI_ManaFillImage;
[Tooltip("are we casting a spell? Checked = Yes, unchecked = NO")]
public bool IsSpellCasting;
#endregion
#region strength
[Header("--STRENGTH--")]
[Tooltip("enable Strength use? checked = Yes, unchecked = NO")]
public bool UseStrength;
public int CurrentStrength;
public int MaxStrength = 18;
[Tooltip("a integer to multiply by players level to get new health bonus on level up")]
public int StrengthMultiplier = 15;
[Tooltip("a float value that determines how fast your hunger increases")]
public float StrengthModifier = .1f;
[Tooltip("a UIImage set to type [FILL] and dragged here to display a Current/Max Strength HUD, leave blank if you do not want to use this feature")]
public Image UI_StrengthFillImage;
#endregion
}
[Header("______ ATTRIBUTE SYSTEM _____________________")]
[Tooltip("Here you can enable/disable and set certain attributes of a generic character system")]
public AttributePlayer PlayerAttibutes;
#endregion
#region Extras
[System.Serializable]
public class extras
{
#region Play Time
[System.Serializable]
public class PlayersTime
{
[Tooltip("enable amount if time played? checked = YES, unchecked = NO")]
public bool EnablePlaytime;
[HideInInspector]
public int playtime = 0;
public int seconds = 0;
public int minutes = 0;
public int hours = 0;
public int days = 0;
[Tooltip("a UItext to display current day/hour/minute/second HUD of playtime, leave blank if you do not want to use this feature")]
public Text PlaytimeUIText;
}
[Header("______ PLAYTIME _____________________")]
[Tooltip("Here you can enable/disable overall playtime of character system")]
public PlayersTime Playtime;
#endregion
#region Armor System
[System.Serializable]
public class ArmorCSystem
{
public GameObject currentWeaponinRightHand;
public GameObject currentWeaponinLeftHand;
public GameObject currentArmorChest;
public GameObject currentArmorHead;
public GameObject currentArmorLHand;
public GameObject currentArmorRHand;
public GameObject currentArmorLWrist;
public GameObject currentArmorRWrist;
public GameObject currentArmorBelt;
public GameObject currentArmorBack;
public GameObject currentArmorShoulders;
public GameObject currentArmorShirt;
public GameObject currentArmorLegs;
public GameObject currentArmorFeet;
public GameObject currentRightHandRing;
public GameObject currentLeftHandRing;
}
[Header("______ ARMOR SYSTEM _____________________")]
[Tooltip("Here you can enable/disable and set certain features of a generic armor system - currently in development")]
public ArmorCSystem ArmorSystem;
#endregion
#region CheatCodes
[System.Serializable]
public class Cheaters
{
[Tooltip("enable godmode? checked = YES, unchecked = NO : in godmode your health and stamina are set to 99999")]
public bool GodMode;
[HideInInspector]
public float OldCurrentHealth; // get old value of health
[HideInInspector]
public float OldCurrentStamina; // get old value of stamina
[HideInInspector]
public float OldCurrentMaxHealth; // get old value of max health
[HideInInspector]
public float OldCurrentMaxStamina; // get old value of max stamina
}
[Header("______ CHEATCODES _____________________")]
[Tooltip("Here you can enable/disable cheatcodes of character system")]
public Cheaters Cheatcodes;
#endregion
#region Current Objects Stats
[System.Serializable]
public class CurrSystem
{
public bool UseCurrentSystem;
public GameObject currentEnemy;
public float currentDamageGiven;
public float currentDamageReceived;
}
[Header("______ CURRENT OBJECTS __________________________")]
[Tooltip("The current data last recieved/given / not implemented yet")]
public CurrSystem CurrentData;
#endregion
}
[Header("______ EXTRA _____________________")]
[Tooltip("Here you can enable/disable and set certain attributes of a generic character system")]
public extras Extra;
#endregion
#region Hidden Variables
[HideInInspector]
public int m_XP = 0; /// The player's current score.
[HideInInspector]
public int m_level = 1; /// The player's current level.
[HideInInspector]
public float alpha;
private bool DoOnce = true;
private bool PlayHungerOnce;
private bool PlayThirstOnce;
private bool PlayRestOnce;
private bool PlayBodyTempHotOnce;
private bool PlayBodyTempColdOnce;
private bool PlayOutofBreathOnce;
private bool leveled = false;
private const int MinimumLevel = 1; /// The minimum level permitted.
public int Score /// The player's score.
{
get { return m_XP; }
set { m_XP = value; }
}
public int Level
{
/// The player's current level. Specifying a new level will ensure that the
/// new level is clamped to the maximum permitted level.
get { return m_level; }
set { m_level = Mathf.Clamp(value, MinimumLevel, PlayerLevel.m_maximumLevel); }
}
#endregion
public virtual void CheckForLevelUp() // check for level up
{
// if we have reached the maximum level, do nothing
if (m_level >= PlayerLevel.m_maximumLevel) { return; }
// check for the next required score
int nextLevelScore = 0;
// if there are no more scores in the level score progression array
// switch over to linear progression
// otherwise, use the non-linear progression
if (m_level >= PlayerLevel.m_nextLevelScore.Length) { nextLevelScore = (m_level - PlayerLevel.m_nextLevelScore.Length + 1) * PlayerLevel.m_nextLevelScoreProgression; }
else { nextLevelScore = PlayerLevel.m_nextLevelScore[m_level]; }
// if we have the required score to level up, advance to the next level
if (m_XP >= nextLevelScore)
{
m_XP = 0;
m_level = Math.Min(m_level + 1, PlayerLevel.m_maximumLevel);
PlayerLevel.PlayerLifetimeXP = PlayerLevel.PlayerLifetimeXP + PlayerLevel.PlayerCurrentXP;
// calculate level up multipliers //
int ihealth = (m_level) * PlayerLevel.LevelUpFeatures.VHealthMultiplier;
float iStamina = (m_level) * PlayerLevel.LevelUpFeatures.VStaminaMultiplier;
float ihunger = (m_level) * HungerThirstElements.HungerMultiplier;
float ithirst = (m_level) * HungerThirstElements.ThirstMultiplier;
float irest = (m_level) * HungerThirstElements.RestMultiplier;
float ibreath = (m_level) * HungerThirstElements.BreathMutiplier;
float ibodytemp = (m_level) * HungerThirstElements.BodyTempMutiplier;
//
int imana = (m_level) * PlayerAttibutes.ManaMultiplier;
//calculate new health and stamina //
InvectorStats.Vcurrent_health = InvectorBridge.myController.maxHealth + ihealth;
InvectorStats.Vcurrent_stamina = InvectorBridge.myController.maxStamina + iStamina;
//Mana
if (PlayerAttibutes.UseMana)
{
PlayerAttibutes.CurrentMana = PlayerAttibutes.MaxMana + imana;
PlayerAttibutes.MaxMana = PlayerAttibutes.MaxMana + imana;
}
// calculate hunger thirst system//
if (HungerThirstElements.UseHunger == true)
{
HungerThirstElements.CurrentHunger = HungerThirstElements.MaxHunger + ihunger;
HungerThirstElements.MaxHunger = HungerThirstElements.MaxHunger + ihunger;
}
if (HungerThirstElements.UseThirst == true)
{
HungerThirstElements.CurrentThirst = HungerThirstElements.MaxThirst + ithirst;
HungerThirstElements.MaxThirst = HungerThirstElements.MaxThirst + ithirst;
}
if (HungerThirstElements.UseRest == true)
{
HungerThirstElements.CurrentRest = HungerThirstElements.MaxRest + irest;
HungerThirstElements.MaxRest = HungerThirstElements.MaxRest + irest;
}
if (HungerThirstElements.UseBreath == true)
{
HungerThirstElements.CurrentBreath = HungerThirstElements.MaxBreath + ibreath;
HungerThirstElements.MaxBreath = HungerThirstElements.MaxBreath + ibreath;
}
if (HungerThirstElements.UseBodyTemp == true)
{
HungerThirstElements.CurrentBodyTemp = HungerThirstElements.MaxBodyTemp + ibodytemp;
HungerThirstElements.MaxBodyTemp = HungerThirstElements.MaxBodyTemp + ibodytemp;
}
// update Vcontroller new health and new stamina //
InvectorBridge.myController.currentHealth = InvectorStats.Vcurrent_health;
InvectorBridge.myController.currentStamina = InvectorStats.Vcurrent_stamina;
InvectorBridge.myController.maxHealth = InvectorStats.Vcurrent_health;
InvectorBridge.myController.maxStamina = InvectorStats.Vcurrent_stamina;
// update player level and calculate new XP to next level //
PlayerLevel.PlayersLevel = m_level;
PlayerLevel.current_xp_to_nxt_Level = PlayerLevel.m_nextLevelScore[m_level];
//clear all stats on level up
PlayerLevel.PlayerCurrentXP = 0;
HungerThirstElements.CurrentHunger = 0;
HungerThirstElements.CurrentThirst = 0;
HungerThirstElements.CurrentRest = 0;
HungerThirstElements.CurrentBreath = 0;
HungerThirstElements.CurrentBodyTemp = HungerThirstElements.MaxBodyTemp;
//
//play sound effect if any
if (PlayerLevel.LevelUpFeatures.m_LevelUpSound != null)
{
PlayNextLevelSound(PlayerLevel.LevelUpFeatures.m_LevelUpSound);
}
// if level up particle VFX isnt empty instantiate FX at Player position //
if (PlayerLevel.LevelUpFeatures.LevelUpVFX != null)
{
Instantiate(PlayerLevel.LevelUpFeatures.LevelUpVFX, transform.position + PlayerLevel.LevelUpFeatures.LevelUpVFXOffset, Quaternion.identity);
// Instantiate(LevelUpFeatures.LevelUpVFX, this.gameObject.transform.position, this.gameObject.transform.rotation);
}
//
if (PlayerLevel.LevelUpUIElements.levelUpScreenOverlay != null)
{
PlayerLevel.LevelUpUIElements.levelUpScreenOverlay.CrossFadeAlpha(1f, 0.001f, false); // fade in full screen overlay
PlayerLevel.LevelUpUIElements.levelUpScreenOverlay.CrossFadeAlpha(0.0f, PlayerLevel.LevelUpUIElements.levelUpScreenOverlayTime, false);
}
// play level up splash text and update GUI level if text is filled in
if (PlayerLevel.LevelUpUIElements.UI_MyLevelUpSplashText != null)
{
PlayerLevel.LevelUpUIElements.UI_MyLevelUpSplashText.CrossFadeAlpha(1f, 0.01f, false);
PlayerLevel.LevelUpUIElements.UI_MyLevelUpSplashText.text = "You've reached Level: " + Level.ToString();
PlayerLevel.LevelUpUIElements.UI_MyLevelUpSplashText.CrossFadeAlpha(0.0f, PlayerLevel.LevelUpUIElements.SplashTexttime, false);
}
//adjust UI level number
if (PlayerLevel.LevelUpUIElements.UI_MyLevelNumber != null)
{
PlayerLevel.LevelUpUIElements.UI_MyLevelNumber.text = "Level: " + Level.ToString();
}
leveled = true;
}
} // // close Check for LevelUp
void Start() // Use this for initialization
{
#region Invector Bridge
if (InvectorBridge.myController != null) // if controller is not active ignore
{
#region Playtime
if (Extra.Playtime.EnablePlaytime) { StartCoroutine("Playtimer"); }
#endregion
InvectorStats.Vcurrent_health = InvectorBridge.myController.currentHealth;
InvectorStats.Vcurrent_stamina = InvectorBridge.myController.currentStamina;
InvectorStats.VMaxhealth = InvectorBridge.myController.maxHealth; // get invector MaxHealth
InvectorStats.VMaxstamina = InvectorBridge.myController.maxStamina; //get invector MaxStamina
// InvectorStats.RecoveryStats.VhealthRecovery = InvectorBridge.myController.healthRecovery;
// InvectorStats.RecoveryStats.VhealthRecoveryDelay = InvectorBridge.myController.healthRecoveryDelay;
// InvectorStats.RecoveryStats.VstaminaRecovery = InvectorBridge.myController.staminaRecovery;
PlayerLevel.current_xp_to_nxt_Level = PlayerLevel.m_nextLevelScore[m_level]; // get XP to next level
PlayerLevel.PlayersLevel = m_level;
HungerThirstElements.CurrentBodyTemp = HungerThirstElements.NormalBodyTemp;
if (PlayerAttibutes.UseMana)
{
PlayerAttibutes.CurrentMana = PlayerAttibutes.MaxMana;
}
if (PlayerLevel.LevelUpUIElements.UI_MyLevelNumber != null)
{
PlayerLevel.LevelUpUIElements.UI_MyLevelNumber.text = "Level: " + Level.ToString(); //update level to start level
}
if (PlayerLevel.LevelUpUIElements.UI_XPFillImage != null)
{
PlayerLevel.LevelUpUIElements.UI_XPFillImage.fillAmount = 0; //empty XPbar graphic
}
if (HungerThirstElements.UI_HungerFillImage != null)
{
HungerThirstElements.UI_HungerFillImage.fillAmount = 0; //empty hunger bar graphic
}
if (HungerThirstElements.UI_ThirstFillImage != null)
{
HungerThirstElements.UI_ThirstFillImage.fillAmount = 0; //empty thirst graphic
}
if (HungerThirstElements.UI_RestFillImage != null)
{
HungerThirstElements.UI_RestFillImage.fillAmount = 0; //empty rest bar graphic
}
if (HungerThirstElements.UI_BreathFillImage != null)
{
HungerThirstElements.UI_BreathFillImage.fillAmount = 0; //empty breath graphic
}
if (HungerThirstElements.UI_BodyTempFillImage != null)
{
HungerThirstElements.UI_BodyTempFillImage.fillAmount = HungerThirstElements.NormalBodyTemp; //empty bodytemp graphic
}
if (PlayerLevel.LevelUpUIElements.UI_MyLevelUpSplashText != null)
{
PlayerLevel.LevelUpUIElements.UI_MyLevelUpSplashText.text = ""; //clear level up splash text
}
if (PlayerLevel.LevelUpUIElements.UI_XPGainedSplashText != null)
{
PlayerLevel.LevelUpUIElements.UI_XPGainedSplashText.text = ""; //clear XP gained splash text
}
if (HungerThirstElements.UI_FrozenScreenOverlay != null)
{
HungerThirstElements.UI_FrozenScreenOverlay.CrossFadeAlpha(0f, 0f, false);
}
if (HungerThirstElements.UI_HeatedScreenOverlay != null)
{
HungerThirstElements.UI_HeatedScreenOverlay.CrossFadeAlpha(0f, 0f, false);
}
if (HungerThirstElements.UI_OutOfBreathOverlay != null)
{
HungerThirstElements.UI_OutOfBreathOverlay.CrossFadeAlpha(0f, 0f, false);
}
if (PlayerLevel.LevelUpUIElements.levelUpScreenOverlay != null)
{
PlayerLevel.LevelUpUIElements.levelUpScreenOverlay.CrossFadeAlpha(0f, 0f, false);
}
if (HungerThirstElements.UI_HungerScreenOverlay != null)
{
HungerThirstElements.UI_HungerScreenOverlay.CrossFadeAlpha(0f, 0f, false);
}
if (HungerThirstElements.UI_ThirstScreenOverlay != null)
{
HungerThirstElements.UI_ThirstScreenOverlay.CrossFadeAlpha(0f, 0f, false);
}
if (HungerThirstElements.UI_RestScreenOverlay != null)
{
HungerThirstElements.UI_RestScreenOverlay.CrossFadeAlpha(0f, 0f, false);
}
}
#endregion
}
void Update() // Update is called once per frame
{
#region Invector Bridge
if (InvectorBridge.myController != null) // if controller is not active ignore
{
CheckForLevelUp(); //check if we have enough XP to gain a level
if (leveled == true) { /* if i want to put something later */ }
#region InvectorStats
InvectorStats.Vcurrent_health = InvectorBridge.myController.currentHealth;
InvectorStats.Vcurrent_stamina = InvectorBridge.myController.currentStamina;
InvectorStats.VMaxhealth = InvectorBridge.myController.maxHealth; // get invector MaxHealth
InvectorStats.VMaxstamina = InvectorBridge.myController.maxStamina; //get invector MaxStamina
InvectorStats.RecoveryStats.VhealthRecovery = InvectorBridge.myController.healthRecovery;
InvectorStats.RecoveryStats.VhealthRecoveryDelay = InvectorBridge.myController.healthRecoveryDelay;
InvectorStats.RecoveryStats.VstaminaRecovery = InvectorBridge.myController.staminaRecovery;
#endregion
if (HungerThirstElements.CurrentHunger >= HungerThirstElements.MaxHunger /2 )
{
InvectorStats.Vcurrent_health = InvectorStats.Vcurrent_health - 1f;
}
// added 7/30/2016 josh edit // adding in a new blood GUI splash screen on damage
if (GetComponent<vThirdPersonMotor>().hud.damaged == true)
{
// Debug.Log("got hit");
if (InvectorBridge.DamageSplashScreens.Length > 0)
{
GetComponentInParent<vThirdPersonMotor>().hud.damageImage = InvectorBridge.DamageSplashScreens[UnityEngine.Random.Range(0, InvectorBridge.DamageSplashScreens.Length)];
}
}
float HealthPercent = InvectorBridge.myController.currentHealth / InvectorBridge.myController.maxHealth;
if (InvectorBridge.UI_HealthFillImage != null) { InvectorBridge.UI_HealthFillImage.fillAmount = HealthPercent; }
float StaminaPercent = InvectorBridge.myController.currentStamina / InvectorBridge.myController.maxStamina;
if (InvectorBridge.UI_StaminaFillImage != null) { InvectorBridge.UI_StaminaFillImage.fillAmount = HealthPercent; }
// end added edit 7/30/2016 josh edit
#region Playtime
if (Extra.Playtime.EnablePlaytime)
{
if (Extra.Playtime.PlaytimeUIText != null)
{
Extra.Playtime.PlaytimeUIText.GetComponent<Text>().text = "You've stayed alive : " + Extra.Playtime.days.ToString() + ": Days " + Extra.Playtime.hours.ToString() + ": Hours " + Extra.Playtime.minutes.ToString() + ": minutes " + Extra.Playtime.seconds.ToString() + ": seconds ";
}
}
#endregion
#region XP
//XP //
float PlayerXpPercent = PlayerLevel.PlayerCurrentXP / PlayerLevel.current_xp_to_nxt_Level; //calculate new XP to next level
if (PlayerLevel.LevelUpUIElements.UI_XPFillImage != null) { PlayerLevel.LevelUpUIElements.UI_XPFillImage.fillAmount = PlayerXpPercent; }
#endregion
#region attributes
//ATTRIBUTES/// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
/// // Mana ///
if (PlayerAttibutes.UseMana == true)
{
float ManaPercent = PlayerAttibutes.CurrentMana / PlayerAttibutes.MaxMana;
if (PlayerAttibutes.UI_ManaFillImage != null) { PlayerAttibutes.UI_ManaFillImage.fillAmount = ManaPercent; }
///
if (PlayerAttibutes.CurrentMana < PlayerAttibutes.MaxMana && !PlayerAttibutes.IsSpellCasting) { PlayerAttibutes.CurrentMana += Time.deltaTime * PlayerAttibutes.ManaRegenModifier; } // if get too hungry lose stamina
if (PlayerAttibutes.CurrentMana > 0 && PlayerAttibutes.IsSpellCasting) { PlayerAttibutes.CurrentMana -= PlayerAttibutes.ManaCastingModifier * Time.deltaTime; }
}
#endregion
#region HungerThirstSystem
//HUNGER THIRST SYSTEM /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
/// // hunger ///
if (HungerThirstElements.UseHunger == true)
{
float HungerPercent = HungerThirstElements.CurrentHunger / HungerThirstElements.MaxHunger;
if (HungerThirstElements.UI_HungerFillImage != null) { HungerThirstElements.UI_HungerFillImage.fillAmount = HungerPercent; }
///
if (HungerThirstElements.CurrentHunger < HungerThirstElements.MaxHunger) { HungerThirstElements.CurrentHunger += Time.deltaTime * HungerThirstElements.HungerModifier; } // if get too hungry lose stamina
if (HungerThirstElements.CurrentHunger >= HungerThirstElements.MaxHunger) { InvectorBridge.myController.currentStamina -= Time.deltaTime * 65; }
if (HungerThirstElements.UI_HungerScreenOverlay != null)
{
if (HungerThirstElements.CurrentHunger > HungerThirstElements.MaxHunger / 1.1f)
{
HungerThirstElements.UI_HungerScreenOverlay.CrossFadeAlpha(1f, HungerThirstElements.UI_HungerScreenOverlayTime, false); // fade in full screen overlay
}
else
{
HungerThirstElements.UI_HungerScreenOverlay.CrossFadeAlpha(0.0f, HungerThirstElements.UI_HungerScreenOverlayTime, false);
}
}
//
if (HungerThirstElements.CurrentHunger < (HungerThirstElements.MaxHunger / 1.1f)) { PlayHungerOnce = false; }
//play sound effect if any
if (HungerThirstElements.HungerCriticalSound != null && HungerThirstElements.CurrentHunger >= (HungerThirstElements.MaxHunger / 1.06f) && PlayHungerOnce == false)
{
PlayNextLevelSound(HungerThirstElements.HungerCriticalSound);
PlayHungerOnce = true;
}
}
/// // thirst ///
if (HungerThirstElements.UseThirst == true)
{
float ThirstPercent = HungerThirstElements.CurrentThirst / HungerThirstElements.MaxThirst;
if (HungerThirstElements.UI_ThirstFillImage != null) { HungerThirstElements.UI_ThirstFillImage.fillAmount = ThirstPercent; }
//
if (HungerThirstElements.CurrentThirst < HungerThirstElements.MaxThirst) { HungerThirstElements.CurrentThirst += Time.deltaTime * HungerThirstElements.ThirstModifier; } // if get too thirsty lose health
if (HungerThirstElements.CurrentThirst >= HungerThirstElements.MaxThirst) { InvectorBridge.myController.currentHealth -= Time.deltaTime * 2;
}
if (HungerThirstElements.UI_ThirstScreenOverlay != null)
{
if (HungerThirstElements.CurrentThirst > HungerThirstElements.MaxThirst / 1.1f)
{
HungerThirstElements.UI_ThirstScreenOverlay.CrossFadeAlpha(1f, HungerThirstElements.UI_ThirstScreenOverlayTime, false); // fade in full screen overlay
}
else
{
HungerThirstElements.UI_ThirstScreenOverlay.CrossFadeAlpha(0.0f, HungerThirstElements.UI_ThirstScreenOverlayTime, false);
}
}
//
if (HungerThirstElements.CurrentThirst < (HungerThirstElements.MaxThirst / 1.1f)) { PlayThirstOnce = false; }
//play sound effect if any
if (HungerThirstElements.ThirstCriticalSound != null && HungerThirstElements.CurrentThirst >= (HungerThirstElements.MaxThirst / 1.06f) && PlayThirstOnce == false)
{
PlayNextLevelSound(HungerThirstElements.ThirstCriticalSound);
PlayThirstOnce = true;
}
}
/// // rest ///
if (HungerThirstElements.UseRest == true)
{
float RestPercent = HungerThirstElements.CurrentRest / HungerThirstElements.MaxRest;
if (HungerThirstElements.UI_RestFillImage != null) { HungerThirstElements.UI_RestFillImage.fillAmount = RestPercent; }
//
if (HungerThirstElements.CurrentRest < HungerThirstElements.MaxRest) { HungerThirstElements.CurrentRest += Time.deltaTime * HungerThirstElements.RestModifier; }
if (HungerThirstElements.CurrentRest >= HungerThirstElements.MaxRest) { /* do stuff if tired*/
}
if (HungerThirstElements.UI_RestScreenOverlay != null)
{
if (HungerThirstElements.CurrentRest > HungerThirstElements.MaxRest / 1.1f)
{
HungerThirstElements.UI_RestScreenOverlay.CrossFadeAlpha(1f, HungerThirstElements.UI_RestScreenOverlayTime, false); // fade in full screen overlay
}
else
{
HungerThirstElements.UI_RestScreenOverlay.CrossFadeAlpha(0.0f, HungerThirstElements.UI_RestScreenOverlayTime, false);
}
}
if (HungerThirstElements.CurrentRest < (HungerThirstElements.MaxRest / 1.1f)) { PlayRestOnce = false; }
//play sound effect if any
if (HungerThirstElements.RestCriticalSound != null && HungerThirstElements.CurrentRest >= (HungerThirstElements.MaxRest / 1.06f) && PlayRestOnce == false)
{
PlayNextLevelSound(HungerThirstElements.RestCriticalSound);
PlayRestOnce = true;
}
}
/// // breath ///
if (HungerThirstElements.UseBreath == true)
{
float BreathPercent = HungerThirstElements.CurrentBreath / HungerThirstElements.MaxBreath;
if (HungerThirstElements.UI_BreathFillImage != null) { HungerThirstElements.UI_BreathFillImage.fillAmount = BreathPercent; }
//
if (HungerThirstElements.CurrentBreath < HungerThirstElements.MaxBreath + 5 && HungerThirstElements.isHoldingBreath == false)
{
if (HungerThirstElements.CurrentBreath > 0f)
{
HungerThirstElements.CurrentBreath -= Time.deltaTime * 10f;
if (HungerThirstElements.UI_OutOfBreathOverlay != null)
{
HungerThirstElements.UI_OutOfBreathOverlay.CrossFadeAlpha(0f, 5f, false); // fade in full screen overlay
}
}
}
if (HungerThirstElements.CurrentBreath < HungerThirstElements.MaxBreath && HungerThirstElements.isHoldingBreath == true) { HungerThirstElements.CurrentBreath += Time.deltaTime * HungerThirstElements.BreathModifier; }
//
if (HungerThirstElements.CurrentBreath < (HungerThirstElements.MaxBreath / 2)) { PlayOutofBreathOnce = false; }
//play sound effect if any
if (HungerThirstElements.OutOfBreathCriticalSound != null && HungerThirstElements.CurrentBreath >= (HungerThirstElements.MaxBreath / 1.06f) && PlayOutofBreathOnce == false)
{
PlayNextLevelSound(HungerThirstElements.OutOfBreathCriticalSound);
PlayOutofBreathOnce = true;
}
if (HungerThirstElements.CurrentBreath >= HungerThirstElements.MaxBreath)
{ /* do stuff if winded/out of breath*/
if (HungerThirstElements.UI_OutOfBreathOverlay != null)
{
HungerThirstElements.UI_OutOfBreathOverlay.CrossFadeAlpha(1f, 5f, false); // fade in full screen overlay
}
}
}
/// // body temp ///
if (HungerThirstElements.UseBodyTemp == true)
{
float BodyTempPercent = HungerThirstElements.CurrentBodyTemp / HungerThirstElements.MaxBodyTemp;
if (HungerThirstElements.UI_BodyTempFillImage != null) { HungerThirstElements.UI_BodyTempFillImage.fillAmount = BodyTempPercent; }
GettingHot();
GettingCold();
}
#endregion
#region Cheats
if (Extra.Cheatcodes.GodMode && InvectorBridge.myController.currentHealth < 99999f)
{
Extra.Cheatcodes.OldCurrentHealth = InvectorBridge.myController.currentHealth;
Extra.Cheatcodes.OldCurrentStamina = InvectorBridge.myController.currentStamina;
Extra.Cheatcodes.OldCurrentMaxHealth = InvectorBridge.myController.maxHealth;
Extra.Cheatcodes.OldCurrentMaxStamina = InvectorBridge.myController.maxStamina;
InvectorBridge.myController.currentHealth = 99999f;
InvectorBridge.myController.maxHealth = 99999f;
InvectorBridge.myController.currentStamina = 99999f;
InvectorBridge.myController.maxStamina = 99999f;
DoOnce = false;
}
if (!Extra.Cheatcodes.GodMode && DoOnce == false)
{
InvectorBridge.myController.currentHealth = Extra.Cheatcodes.OldCurrentHealth;
InvectorBridge.myController.currentStamina = Extra.Cheatcodes.OldCurrentStamina;
InvectorBridge.myController.maxHealth = Extra.Cheatcodes.OldCurrentMaxHealth;
InvectorBridge.myController.maxStamina = Extra.Cheatcodes.OldCurrentMaxStamina;
DoOnce = true;
}
#endregion
} // close if controller null
#endregion
} // close void Update()
public void PlayNextLevelSound(AudioClip playsound) // Play the audio for level up sound.
{
GameObject audioObject = null;
if (InvectorBridge.audioSource != null)
audioObject = Instantiate(InvectorBridge.audioSource.gameObject, this.transform.position, Quaternion.identity) as GameObject;
else
{
audioObject = new GameObject("audioObject");
audioObject.transform.position = this.transform.position;
}
if (audioObject != null)
{
var source = audioObject.gameObject.GetComponent<AudioSource>();
var clip = playsound;
source.PlayOneShot(clip);
}
}
public void AdjustLevel(int levels) // Adjust the current level by the specified number of levels
/// Adjust the current level by the specified number of levels. Negative
/// values will subtract levels. Does not adjust the score to match. The
/// new level will be clamped to within the maximum permitted level.
/// int levels is Number of levels to adjust the current level
{
m_level = Mathf.Clamp(m_level + levels, MinimumLevel, PlayerLevel.m_maximumLevel);
}
public void AdjustScore(int iXP) // Adjust the score
{
m_XP += iXP;
}
public void GettingHot()
{
if (HungerThirstElements.isGettingHot) // getting hot
{
if (HungerThirstElements.CurrentBodyTemp <= HungerThirstElements.NormalBodyTemp + 10)
{
if (HungerThirstElements.UI_HeatedScreenOverlay != null)
{
HungerThirstElements.UI_HeatedScreenOverlay.CrossFadeAlpha(0f, 5f, false); // fade in full screen overlay
}
}
if (HungerThirstElements.CurrentBodyTemp <= HungerThirstElements.MaxBodyTemp && (HungerThirstElements.CurrentBodyTemp > HungerThirstElements.NormalBodyTemp - 1))
{
HungerThirstElements.CurrentBodyTemp += Time.deltaTime * HungerThirstElements.BodyTempModifier; //raise body temp
}
//play sound effect if any
if (HungerThirstElements.HeatedCriticalSound != null && HungerThirstElements.CurrentBodyTemp >= (HungerThirstElements.MaxBodyTemp / 1.08f) && PlayBodyTempHotOnce == false)
{
PlayNextLevelSound(HungerThirstElements.HeatedCriticalSound);
PlayBodyTempHotOnce = true;
}
if (HungerThirstElements.CurrentBodyTemp >= HungerThirstElements.NormalBodyTemp + 20f)
{
if (HungerThirstElements.UI_HeatedScreenOverlay != null)
{
HungerThirstElements.UI_HeatedScreenOverlay.CrossFadeAlpha(1f, 5f, false); // fade in full screen overlay
}
}
}
if (HungerThirstElements.isGettingHot == false) // getting hot
{
if (HungerThirstElements.CurrentBodyTemp > HungerThirstElements.NormalBodyTemp)
{
HungerThirstElements.CurrentBodyTemp -= Time.deltaTime * HungerThirstElements.BodyTempModifier; // lower body temp to normal
}
if (HungerThirstElements.CurrentBodyTemp < HungerThirstElements.MaxBodyTemp + 20)
{
if (HungerThirstElements.UI_HeatedScreenOverlay != null)
{
HungerThirstElements.UI_HeatedScreenOverlay.CrossFadeAlpha(0f, 5f, false);
}
}
}
}
public void GettingCold()
{
if (HungerThirstElements.isGettingCold) // getting cold
{
if (HungerThirstElements.CurrentBodyTemp <= HungerThirstElements.NormalBodyTemp - 10f)
{
if (Camera.main.GetComponent<StartFrost>() != null) //custom frosting screen unavailable to public
{
Camera.main.GetComponent<StartFrost>().startfrosting = true;//custom frosting screen unavailable to public
}
}
if (HungerThirstElements.CurrentBodyTemp >= -10f)
{
HungerThirstElements.CurrentBodyTemp -= Time.deltaTime * HungerThirstElements.BodyTempModifier; //lower body temp
}
if (HungerThirstElements.CurrentBodyTemp < HungerThirstElements.NormalBodyTemp - 30f)
{
if (HungerThirstElements.UI_FrozenScreenOverlay != null)
{
HungerThirstElements.UI_FrozenScreenOverlay.CrossFadeAlpha(1f, 5f, false); // fade in full screen overlay
}
if (Camera.main.GetComponent<StartFrost>() != null) //custom frosting screen unavailable to public
{
Camera.main.GetComponent<StartFrost>().MaxFrostAllowed = 0.38f;//custom frosting screen unavailable to public
}
}
if (HungerThirstElements.CurrentBodyTemp <= HungerThirstElements.NormalBodyTemp - 50f)
{
//Camera.main.GetComponentInChildren<UnityStandardAssets.ImageEffects.MotionBlur>().enabled = true; // enable motion blur if you have it added to camera
}
if (HungerThirstElements.CurrentBodyTemp > HungerThirstElements.NormalBodyTemp - 50f)
{
//Camera.main.GetComponentInChildren<UnityStandardAssets.ImageEffects.MotionBlur>().enabled = false; // disable motion blur if you have it added to camera
}
//play sound effect if any
if (HungerThirstElements.FrozenCriticalSound != null && HungerThirstElements.CurrentBodyTemp < (HungerThirstElements.NormalBodyTemp / 2.55f) && PlayBodyTempColdOnce == false)
{
PlayNextLevelSound(HungerThirstElements.FrozenCriticalSound);
PlayBodyTempColdOnce = true;
}
}
if (HungerThirstElements.isGettingCold == false) // getting cold false
{
if (HungerThirstElements.CurrentBodyTemp >= (HungerThirstElements.NormalBodyTemp - 1) && HungerThirstElements.CurrentBodyTemp <= (HungerThirstElements.NormalBodyTemp + 1)) { PlayBodyTempColdOnce = false; PlayBodyTempHotOnce = false; }
if (HungerThirstElements.CurrentBodyTemp < HungerThirstElements.NormalBodyTemp)
{
HungerThirstElements.CurrentBodyTemp += Time.deltaTime * HungerThirstElements.BodyTempModifier; //lower body temp
}
if (HungerThirstElements.CurrentBodyTemp > HungerThirstElements.NormalBodyTemp - 20f)
{
if (Camera.main.GetComponent<StartFrost>() != null) //custom frosting screen unavailable to public
{
Camera.main.GetComponent<StartFrost>().MaxFrostAllowed = 0.33f;//custom frosting screen unavailable to public
Camera.main.GetComponent<StartFrost>().startfrosting = false;//custom frosting screen unavailable to public
}
if (HungerThirstElements.UI_FrozenScreenOverlay != null)
{
HungerThirstElements.UI_FrozenScreenOverlay.CrossFadeAlpha(0f, 5f, false);
}
}
if (HungerThirstElements.CurrentBodyTemp > 0f)
{
if (HungerThirstElements.UI_FrozenScreenOverlay != null)
{
HungerThirstElements.UI_FrozenScreenOverlay.CrossFadeAlpha(0f, 5f, false);
}
}
if (HungerThirstElements.CurrentBodyTemp > 0f)
{
if (HungerThirstElements.UI_FrozenScreenOverlay != null)
{
HungerThirstElements.UI_FrozenScreenOverlay.CrossFadeAlpha(0f, 5f, false);
}
if (Camera.main.GetComponent<StartFrost>() != null) //custom frosting screen unavailable to public
{
Camera.main.GetComponent<StartFrost>().MaxFrostAllowed = 0.33f;//custom frosting screen unavailable to public
}
}
}
}
private IEnumerator Playtimer()
{
while (true)
{
yield return new WaitForSeconds(1);
Extra.Playtime.playtime += 1;
Extra.Playtime.seconds = (Extra.Playtime.playtime % 60);
Extra.Playtime.minutes = (Extra.Playtime.playtime / 60) % 60;
Extra.Playtime.hours = (Extra.Playtime.playtime / 3600) % 24;
Extra.Playtime.days = (Extra.Playtime.playtime / 86400) % 365;
}
}
}
------------------------------------------------------------------------------------
InvectorAI-Addon script snippet
Next create another c# script and call it - InvectorAIAddon -
and open it up and erase all inside and copy/paste this code
using UnityEngine;
using System.Collections;
using Invector.CharacterController;
using System.Collections.Generic;
public class InvectorAIAddon : MonoBehaviour
{
[Header("______ STATS _____________________________")]
public int XPGainedOnDeath = 100; //amount of XP for killing
public float CurrentHealth; //current hp
[System.Serializable]
public class DropItemonDeath
{
public GameObject[] DropRandomItemOnDeathPrefab;
[Range(0, 100)]
public float DropItemChancePercent = 15f; //out of 100
public Vector3 dropItemOffset = new Vector3(0.5f, 0.5f, 0.5f);
}
[Header("______ LOOT SYSTEM _____________________________")]
[Tooltip("Here you can add a random item drop from an array of objects")]
public DropItemonDeath LootDropSystem;
private GameObject Player;//Player
private bool DoOnce;
void Update()// Update is called once per frame
{
Player = (GameObject)GameObject.FindGameObjectWithTag("Player"); // find the player /single player method only atm
if (GetComponent<Invector.vCharacter>() != null) // if controller is not active ignore
{
CurrentHealth = GetComponent<Invector.vCharacter>().currentHealth; // get enemies current health
if (CurrentHealth <= .01f) // if health is less than trigger death events
{
iDied(); // death event
}
}
}
public void iDied() // death events
{
if (DoOnce == false)
{
if (Player.GetComponentInParent<InvectorAddOn>() != null) // if invector addon doesnt exist ignore
{
Player.GetComponentInParent<InvectorAddOn>().m_XP = Player.GetComponentInParent<InvectorAddOn>().m_XP + XPGainedOnDeath;
Player.GetComponentInParent<InvectorAddOn>().PlayerLevel.PlayerCurrentXP = Player.GetComponentInParent<InvectorAddOn>().PlayerLevel.PlayerCurrentXP + XPGainedOnDeath;
if (Player.GetComponentInParent<InvectorAddOn>().PlayerLevel.LevelUpUIElements.UI_XPGainedSplashText != null) // if spash text gui is undefined ignore
{
Player.GetComponentInParent<InvectorAddOn>().PlayerLevel.LevelUpUIElements.UI_XPGainedSplashText.CrossFadeAlpha(1f, 0.01f, false);
Player.GetComponentInParent<InvectorAddOn>().PlayerLevel.LevelUpUIElements.UI_XPGainedSplashText.text = "XP Gained: " + XPGainedOnDeath.ToString();
Player.GetComponentInParent<InvectorAddOn>().PlayerLevel.LevelUpUIElements.UI_XPGainedSplashText.CrossFadeAlpha(0.0f, Player.GetComponentInParent<InvectorAddOn>().PlayerLevel.LevelUpUIElements.XPGainedSplashTextTime, false);
}
//do we need to drop an item?
if (LootDropSystem.DropRandomItemOnDeathPrefab.Length > 0)
{
int iRndB = Random.Range(1, 99);
if (iRndB<LootDropSystem.DropItemChancePercent)
{
DropRandomItem();
}
}
}
DoOnce = true;
}
}
public void DropRandomItem()
{
GameObject DroppedItem = LootDropSystem.DropRandomItemOnDeathPrefab[Random.Range(0, LootDropSystem.DropRandomItemOnDeathPrefab.Length)];
Instantiate(DroppedItem, transform.position + LootDropSystem.dropItemOffset, Quaternion.identity);
}
}
Steps for Player:
1) Add the InvectorAddOn to your ThirdPersonPlayer
2) in the Inspector open the Invector Bridge part and assign your player to the MyController field (this step is important)
3) in your Invector3rdPersonController->Scripts->Footstep->Audiosource folder there is an "audiosource" prefab, drag it into the Audiosource component of the InvectorBridge area.
4) optionally mess around with all the other features. any questions about how something works or what it does feel free to ask or mssg me.
Steps for Enemies:
1) add the InvectorAIAddon script to any enemies
2) adjust XP and if you want random item drops on death.
that's it.
hope it helps someone out.
NOTES: the UI_Fill textures components are UI Textures created under the InvectorHUD (just rightclick-create new UI-Texture and adjust anchors how you want. set Image texture to Fill (however you want, radial, bar etc) the code will handle making the values adjust.
the UI Overlay textures are/were designed for full screen awareness similar to blood splat screen on take damage (think screen changing blue hue when temp is below freezing, turns red when overheated, blurry when holding breath past max, etc)
Important: if using the UI elements, be sure that on your UI image that you have it enabled otherwise your UI's will not work properly.
////////VIDEOS////////////