can anyone help me with equip/unequip a wepon?
hi guys please help me , i have a player when i press E key he equip the the weapon ,but i want when i press E key again yo unequip the weapon , and the weapon return to its original position on player "left upleg"
this is my script; using UnityEngine; using System.Collections;
public class WieldWeapon : MonoBehaviour {
Animator anim;
public GameObject sword;
public GameObject hand; void Start() {
anim = GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
anim.SetTrigger("Draw");
sword.transform.parent = hand.transform; //Parenting this item to the hand bone position
sword.transform.localPosition = new Vector3(0.1170032f, -0.1580014f, 0.07697155f); // centering the sword handle
sword.transform.localRotation = Quaternion.identity; //must point y local, so reset rotation
sword.transform.localRotation = Quaternion.Euler(38.68549f, 13.8611f, 104.8913f); //and rotate the sword accordingly
}
}
}
Answer by Ali-hatem · Mar 19, 2016 at 04:07 PM
let us deal with press E key now use a bool variable :
bool equiped = false;
if (Input.GetKeyDown(KeyCode.E) && !equiped )
{
//draw the sword
equiped = true;
}
else if (Input.GetKeyDown(KeyCode.E) && equiped )
{
//hide the sword
equiped = false;
}
thanks a lot man , sometimes my had freezes , really thanks
Your answer
Follow this Question
Related Questions
I want my script to wait 2 seconds before continue in a condition, in update, using C# 2 Answers
Need help with c# 1 Answer
I create material with script but it does not render right 0 Answers
Creating Splines from empties in script 0 Answers
How to fix that type of error(java.lang.illegalAccessException) 0 Answers