// Use this for initialization void Start() { swordScript = GetComponent("PlayerShooter_Sword") as PlayerShooter_Sword; staffScript = GetComponent("PlayerShooter_Staff") as PlayerShooter_Staff; // TODO: The following logic is not very scalable. // An additional condition for each possible weapon-possession combination // is only feasible for this demo (in which there are only two weapons) if (hasSword == false || hasStaff == false) { currentWeapon = "none"; weapons = null; } else if (hasSword == true && hasStaff == false) { // Set the current weapon and the array of possessed weapons currentWeapon = "fireSword"; weapons = new string[] { "fireSword" }; // Set the player sprite and its animation based on the weapon held GetComponent <SpriteRenderer>().sprite = (Sprite)Resources.Load <Sprite>("player_armed_sprite_01_512"); Animator animator = GetComponent <Animator>(); animator.runtimeAnimatorController = (RuntimeAnimatorController)Resources.Load <RuntimeAnimatorController>("player_armed_ANIMCTRL"); } else if (hasStaff) // in this case, if player has the staff he must have already obtained the sword // Set the current weapon and the array of possessed weapons { currentWeapon = "fireStaff"; weapons = new string[] { "fireSword", "fireStaff" }; weaponIndex = 1; // Set the player sprite and its animation based on the weapon held GetComponent <SpriteRenderer>().sprite = (Sprite)Resources.Load <Sprite>("player_staff_sprite_512"); Animator animator = GetComponent <Animator>(); animator.runtimeAnimatorController = (RuntimeAnimatorController)Resources.Load <RuntimeAnimatorController>("player_staff_ANIMCTRL"); } }
void Start() { swordShooter = GameObject.FindWithTag("Player").GetComponent("PlayerShooter_Sword") as PlayerShooter_Sword; if (swordShooter.enabled) { isSwordShot = true; } staffShooter = GameObject.FindWithTag("Player").GetComponent("PlayerShooter_Staff") as PlayerShooter_Staff; if (staffShooter.enabled) { isStaffShot = true; } lifeTimeFrames = (int)(lifeTime / Time.fixedDeltaTime); }