Alors j'ai un inventaire à peux près fonctionnel, mais je m'arrache les cheveux sur un problème. Celui ci est... Mettre de la vie sur une arme. Je m'explique :p
Alors je mets une arme sur un slot spécial. J'utilise cette arme, à chaque coup, elle perd de la vie. Lorsque je suis à 0, je veux supprimer cette arme de l'inventaire (Donc supprimer l'icone "Arme" dans le slot) Et c'est la ou je rencontre un soucis....
voici le script :
Code : Tout sélectionner
using UnityEngine;
public class WeaponController : MonoBehaviour
{
public GameObject weaponHand;
private ItemWeapon weapon;
private Animator animator;
public GameObject weaponModel;
public bool StaffWhiteIsEquip = false;
public bool StaffGreenIsEquip = false;
public int healthStaffBlue = 5;
void Start ()
{
}
void Awake()
{
animator = GetComponent<Animator>();
}
void Update()
{
if (GameController.Instance.GameState != GameStates.Game) return;
animator.SetBool("IsAttack", InputController.Weapon);
if (weapon == null)
{
StaffWhiteIsEquip = false;
StaffGreenIsEquip = false;
}
else
{
// StaffWhiteIsEquip = true;
// StaffGreenIsEquip = true;
}
}
// by the animation event
public void OnAttack()
{
if (weapon == null) return;
PlayerController player = PlayerController.Instance;
if (weapon.itemType == Item.ItemTypes.Staff)
{
ItemWeaponStaff staff = (ItemWeaponStaff)weapon;
if (player.Mana >= staff.mana && healthStaffBlue > 0)
{
Instantiate(staff.bullet, player.mainCamera.transform.position, player.mainCamera.transform.rotation);
player.Mana -= staff.mana;
//Pour supprimer staffBlue (Arme) quand elle n'a plus de vie
if (weapon.model.name == "StaffBlue")
{
healthStaffBlue--;
if (healthStaffBlue <= 0)
//Destroy (weaponModel);
//weapon = null;
}
}
else
{
UIController.Instance.ShowError("Not enought mana");
}
}
else
{
RaycastHit hit;
if (Physics.Raycast(player.mainCamera.transform.position, player.mainCamera.transform.TransformDirection(Vector3.forward), out hit, 4))
{
IHitable hitable = hit.collider.gameObject.GetComponent(typeof(IHitable)) as IHitable;
if (hitable != null)
{
DamageConfig damageWithStreanght = ((ItemWeaponMelee)weapon).damage.Copy();
damageWithStreanght.minPhysical += (int)(damageWithStreanght.minPhysical * 0.05f * PlayerController.Instance.experience.ActualStrenght);
damageWithStreanght.maxPhysical += (int)(damageWithStreanght.maxPhysical * 0.05f * PlayerController.Instance.experience.ActualStrenght);
hitable.Hit(new HitInfo(damageWithStreanght, hit.point, true, HitInfo.HitSources.Player));
}
}
}
}
public void OnSetWeapon(ItemWeapon weapon)
{
this.weapon = weapon;
animator.SetBool("IsAttack", false);
if (weaponModel != null) Destroy(weaponModel);
if (weapon == null)
{
animator.SetInteger("WeaponType", -1);
}
else
{
weaponModel = (GameObject)Instantiate(weapon.model);
weaponModel.transform.parent = weaponHand.transform;
weaponModel.transform.localPosition = Vector3.zero;
weaponModel.transform.localRotation = Quaternion.identity;
//weaponModel.transform.localScale = Vector3.one;
animator.SetInteger("WeaponType", ItemWeapon.GetAnimationId(weapon));
}
if (weapon.model.name == "StaffWhite")// if WeaponModel == StaffWhite
{
StaffWhiteIsEquip = true;
}
else if (weapon.model.name != "StaffWhite")// if WeaponModel == StaffWhite
{
StaffWhiteIsEquip = false;
}
if (weapon.model.name == "StaffGreen")// if WeaponModel == StaffGreen
{
StaffGreenIsEquip = true;
}
else if (weapon.model.name != "StaffGreen" )// if WeaponModel == StaffGreen
{
StaffGreenIsEquip = false;
}
}
}