//make a TRUE copy of this weapon to be used
    public Tds_Weapons CopyWeapon(Tds_Weapons vOld)
    {
        //copy everything for the weapon
        Tds_Weapons vNew = new Tds_Weapons();

        vNew.Rebounce            = vOld.Rebounce;
        vNew.vAmmoSize           = vOld.vAmmoSize;
        vNew.vDmg                = vOld.vDmg;
        vNew.vName               = vOld.vName;
        vNew.vProjectile         = vOld.vProjectile;
        vNew.vWeaponIcon         = vOld.vWeaponIcon;
        vNew.vWeaponObj          = vOld.vWeaponObj;
        vNew.vAimObj             = vOld.vAimObj;
        vNew.vImpactFX           = vOld.vImpactFX;
        vNew.vProjectileSpeed    = vOld.vProjectileSpeed;
        vNew.vShotFX             = vOld.vShotFX;
        vNew.vClipObj            = vOld.vClipObj;
        vNew.vTimeBtwShot        = vOld.vTimeBtwShot;
        vNew.AttackAnimationUsed = vOld.AttackAnimationUsed;
        vNew.vWeaponType         = vOld.vWeaponType;
        vNew.vTimeWaited         = vOld.vTimeWaited;
        vNew.vAmmoCur            = vOld.vAmmoCur;
        vNew.Is2Handed           = vOld.Is2Handed;
        vNew.vBulletAngleList    = vOld.vBulletAngleList;

        //return new tds_weapons
        return(vNew);
    }
    //update current weapon menu
    void UpdateWeaponMenu(Tds_WeaponMenu vCurMenu, Tds_Weapons vCurWeapon)
    {
        if (vCurWeapon != null)
        {
            //enable current menu
            vCurMenu.WepPanel.gameObject.SetActive(true);

            //weapon sprite
            vCurMenu.WeaponSprite.sprite = vCurWeapon.vWeaponIcon;

            //ammo text
            vCurMenu.AmmoValue.text = vCurWeapon.vAmmoCur.ToString() + " / " + vCurWeapon.vAmmoSize;

            //ammo text
            vCurMenu.AmmoValue.text = vCurWeapon.vAmmoCur.ToString() + " / " + vCurWeapon.vAmmoSize;

            //ammo bar % shown
            vCurMenu.AmmoBar.fillAmount = (float)vCurWeapon.vAmmoCur / (float)vCurWeapon.vAmmoSize;

            //check if it's reloading current weapon
            if (IsReloading && vCurWeapon == ListWeapons[vCurWeapIndex])
            {
                vCurMenu.ReloadImg.fillAmount = ((float)TimeToReload / 1f);
            }
            else if (!IsReloading && vCurWeapon.vAmmoCur == 0)
            {
                vCurMenu.ReloadImg.fillAmount = 1f;
            }
            else
            {
                vCurMenu.ReloadImg.fillAmount = 0f;
            }
        }
        else
        {
            //disable the whole menu if there is no weapon there
            vCurMenu.WepPanel.gameObject.SetActive(false);
        }
    }
    public void InitialiseChar(Tds_GameManager vvGameManager)
    {
        //get the gamemanager
        vGameManager = vvGameManager;

        //replace the mouse cursor with this obj
        if (IsPlayer && vGameManager.AimObj != null)
        {
            vAimIcon = vGameManager.AimObj;
            vGameManager.vPlayerText.text = vName;
        }

        //initialise list
        ListWeapons = new List <Tds_Weapons>();

        //initialise weapons from game manager. One place to handle all the game
        foreach (WeaponName vCurName in ListWeaponsName)
        {
            foreach (Tds_Weapons vCurWeapon in vGameManager.vWeaponList)
            {
                if (vCurName.ToString() == vCurWeapon.vWeaponName.ToString())
                {
                    //begin with full Ammo
                    Tds_Weapons vNewWeapon = CopyWeapon(vCurWeapon);
                    vNewWeapon.vAmmoCur = vNewWeapon.vAmmoSize;
                    ListWeapons.Add(vNewWeapon);                     //found the weapon, add it for the player
                }
            }
        }

        //make the 1st weapon the one you have in your hand.
        vCurWeapIndex = 0;

        //now the character is ready
        IsReady = true;
    }
    // Update is called once per frame
    void Update()
    {
        //check if the character is ready
        if (vGameManager != null && IsAlive)
        {
            if (vGameManager.IsReady)
            {
                //get it's weapon ONLY when the game start
                if (!GameStarted)
                {
                    GameStarted = true;
                    ChangeWeapon();
                }

                //check if attacking
                bool    IsAttacking     = false;
                Vector3 vTargetPosition = Camera.main.WorldToScreenPoint(vMainPlayer.transform.position);

                //reduce the waiting time for the next bullet!
                if (!CanAttack && ListWeapons [vCurWeapIndex].vTimeWaited > 0f)
                {
                    ListWeapons [vCurWeapIndex].vTimeWaited -= Time.deltaTime;

                    //check if we waited enought
                    if (ListWeapons [vCurWeapIndex].vTimeWaited <= 0f)
                    {
                        CanAttack = true;
                    }
                }

                if (IsPlayer)
                {
                    //player get mouse position instead of its' own position
                    vTargetPosition = Input.mousePosition;

                    //calculate how far is the cursor from the player
                    Vector3 v3Pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f);
                    v3Pos = Camera.main.ScreenToWorldPoint(v3Pos);

                    //prevent the player to rotate on itself when the cursor is above him
                    if (Vector3.Distance(new Vector3(v3Pos.x, v3Pos.y, 0f), new Vector3(transform.position.x, transform.position.y, 0f)) <= vGameManager.vCursorRange)
                    {
                        CursorIsNear = true;
                    }
                    else
                    {
                        CursorIsNear = false;
                    }

                    if (Input.GetAxis("Vertical") > 0 || Input.GetAxis("Vertical") < 0 || Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Horizontal") < 0)
                    {
                        IsWalking = true;
                    }
                    else
                    {
                        IsWalking = false;
                    }

                    //check if we changed walking status
                    if (IsWalking != LastWalkingStatus)
                    {
                        LastWalkingStatus = IsWalking;
                        vLegAnimator.SetBool("IsWalking", IsWalking);
                    }

                    if (vAimIcon != null && vCurrentIcon == null)
                    {
                        vCurrentIcon = Instantiate(vAimIcon);
                    }
                    else if (vCurrentIcon != null)
                    {
                        Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                        pz.z  = 0;
                        pz.x -= 0.1f;
                        pz.y -= 0.2f;
                        vCurrentIcon.transform.position = pz;
                    }

                    if (Input.GetMouseButton(0))
                    {
                        IsAttacking = true;
                    }

                    //check if the user want to change weapon
                    if (Input.GetAxis("Mouse ScrollWheel") > 0)
                    {
                        GetNextWeapon(1);
                    }
                    else if (Input.GetAxis("Mouse ScrollWheel") < 0)
                    {
                        GetNextWeapon(-1);
                    }

                    //reduce it's time
                    if (IsReloading && TimeToReload > 0f)
                    {
                        TimeToReload -= Time.deltaTime;
                        RefreshWeaponUI();
                    }

                    //get the item
                    if (LootNearby && Input.GetKeyDown("space") && vCurLoot != null)
                    {
                        //check if we already have the weapon and show it
                        bool HasAlreadyWeapon = false;

                        //check if looting give a weapon
                        if (vCurLoot.vItems.GiveWeapon)
                        {
                            //give the right weapon
                            foreach (Tds_Weapons vCurWeapon in vGameManager.vWeaponList)
                            {
                                if (vCurLoot.vItems.vWeaponName.ToString() == vCurWeapon.vWeaponName.ToString())
                                {
                                    foreach (Tds_Weapons vWeapon in ListWeapons)
                                    {
                                        if (vWeapon.vWeaponName == vCurWeapon.vWeaponName)
                                        {
                                            HasAlreadyWeapon = true;
                                        }
                                    }

                                    if (!HasAlreadyWeapon)
                                    {
                                        //get a copy of this weapon
                                        Tds_Weapons vNewWeapon = CopyWeapon(vCurWeapon);

                                        //new weapon is already recharge
                                        vNewWeapon.vAmmoCur = vNewWeapon.vAmmoSize;

                                        //found the weapon, add it for the player
                                        ListWeapons.Add(vNewWeapon);
                                    }
                                }
                            }
                        }

                        if (vGameManager.vItemLootedAnim != null)
                        {
                            //show the itemlooted going up
                            GameObject vNewObj = vGameManager.vItemLootedAnim;

                            //enable it for the very first use
                            vNewObj.SetActive(true);

                            Text vLabel = vNewObj.transform.Find("Label").GetComponent <Text> ();

                            //show different message
                            if (HasAlreadyWeapon)
                            {
                                vLabel.text  = "Already have :";
                                vLabel.color = Color.red;
                            }
                            else
                            {
                                vLabel.color = Color.white;
                                vLabel.text  = "Received :";                                //change info on it
                            }

                            //change info on it
                            Text vText = vNewObj.transform.Find("ItemName").GetComponent <Text> ();

                            //show the right item name
                            vText.text = vCurLoot.vItems.vName;

                            //default color
                            vText.color = Color.green;
                            if (vCurLoot.vItems.vDmgType == WeaponValueType.Average)
                            {
                                vText.color = Color.yellow;
                            }
                            else if (vCurLoot.vItems.vDmgType == WeaponValueType.High)
                            {
                                vText.color = Color.red;
                            }
                            else if (vCurLoot.vItems.vDmgType == WeaponValueType.GODLY)
                            {
                                vText.color = new Color(255f, 0f, 195f, 0f);
                            }

                            //reshow the whole animation
                            vNewObj.GetComponent <Animator> ().SetTrigger("Show");
                        }

                        //destroy loot
                        if (!HasAlreadyWeapon)
                        {
                            GameObject.Destroy(vCurLoot.gameObject);
                            RefreshWeaponUI();
                        }

                        //clear loot
                        vCurLoot = null;
                    }
                }
                else
                {
                    float vDistance = Vector2.Distance(vMainPlayer.transform.position, transform.position);

                    ///////////////AI////////////////
                    if ((vDistance <= 20f || IsAggro) && vDistance >= vGameManager.vMeleeRange)
                    {
                        IsWalking = true;
                        IsChasing = true;
                        SeePlayer = true;
                        IsAggro   = true;
                    }
                    else
                    {
                        //if (vDistance >= vGameManager.vMeleeRange && IsChasing)
                        IsWalking = false;

                        //check if can Melee Attack
                        if (IsChasing && vDistance <= vGameManager.vMeleeRange)
                        {
                            CanMelee    = true;
                            IsAttacking = true;
                        }
                        else
                        {
                            CanMelee = false;
                        }
                    }
                    /////////////////////////////////
                }

                //check if we shoot
                if (IsAttacking && CanAttack)
                {
                    //Melee (don't use any ammo)
                    if (ListWeapons [vCurWeapIndex].vWeaponType == WeaponType.Melee && CanMelee)
                    {
                        //get the amount of time to wait until we can shoot again
                        ListWeapons [vCurWeapIndex].vTimeWaited = ListWeapons [vCurWeapIndex].vTimeBtwShot;

                        //prevent from shooting too many time and wait for the animation to be done
                        CanAttack = false;

                        //animate the hand
                        if (ListWeapons [vCurWeapIndex].AttackAnimationUsed != "")
                        {
                            vBodyAnimator.SetTrigger(ListWeapons [vCurWeapIndex].AttackAnimationUsed);
                        }
                    }
                    else
                    {
                        //RANGED
                        //check if has enought ammo
                        if (ListWeapons [vCurWeapIndex].vAmmoCur > 0)
                        {
                            //get the amount of time to wait until we can shoot again
                            ListWeapons [vCurWeapIndex].vTimeWaited = ListWeapons [vCurWeapIndex].vTimeBtwShot;

                            //prevent from shooting too many time and wait for the animation to be done
                            CanAttack = false;

                            //reduce the ammo by 1
                            ListWeapons [vCurWeapIndex].vAmmoCur--;

                            //animate the hand
                            if (ListWeapons [vCurWeapIndex].AttackAnimationUsed != "")
                            {
                                vBodyAnimator.SetTrigger(ListWeapons [vCurWeapIndex].AttackAnimationUsed);
                            }

                            //create the shot FX
                            GameObject vShotFX = Instantiate(ListWeapons [vCurWeapIndex].vShotFX);
                            vShotFX.transform.position = CurWeaponObj.transform.Find("BulletPos").position;

                            //create the projectile on the aim obj IF EXIST
                            if (ListWeapons [vCurWeapIndex].vProjectile != null)
                            {
                                //create as many shot with the specific angle
                                foreach (float vAngle in ListWeapons[vCurWeapIndex].vBulletAngleList)
                                {
                                    //create the projectile
                                    GameObject vNewProj = Instantiate(ListWeapons [vCurWeapIndex].vProjectile);
                                    vNewProj.transform.position = CurWeaponObj.transform.Find("BulletPos").position;

                                    //calculate the new angle for every shot
                                    Quaternion vtemp = CurWeaponObj.transform.rotation;
                                    vtemp.z += vAngle;
                                    vNewProj.transform.rotation = vtemp;

                                    //send to the projectile everything it need to kill
                                    Tds_Projectile vProj = vNewProj.GetComponent <Tds_Projectile> ();
                                    vGameManager.vProjectileList.Add(vProj);
                                    vProj.vProjFactionType = vFactionType;
                                    vProj.Speed            = ListWeapons [vCurWeapIndex].vProjectileSpeed;
                                    vProj.vDmg             = ListWeapons [vCurWeapIndex].vDmg;
                                    vProj.vGameManager     = vGameManager;
                                    vProj.vRebounce        = ListWeapons [vCurWeapIndex].Rebounce;
                                    vProj.vImpactFX        = ListWeapons [vCurWeapIndex].vImpactFX;
                                    vProj.IsReady          = true;
                                }
                            }
                        }
                        else
                        {
                            if (IsReloading == false)
                            {
                                IsReloading = true;

                                //time until we have fully reloaded
                                TimeToReload = 1f;

                                //recharging animation // then we wait until the animation is complete and tell the character we have ammo!
                                if (vBodyAnimator != null)
                                {
                                    vBodyAnimator.SetTrigger("Reload");
                                }
                            }
                        }

                        //refresh all the weapon on top
                        if (IsPlayer)
                        {
                            RefreshWeaponUI();
                        }
                    }
                }

                //rotate weapon if have one
                Vector3 vBodyPosition = vLeftHandObj.transform.position;

                //calcualte the angle
                Vector3 pos = Camera.main.WorldToScreenPoint(vBodyPosition);
                Vector3 dir = vTargetPosition - pos;

                Quaternion newRotation = Quaternion.LookRotation(dir, Vector3.back);
                newRotation.x = 0f;
                newRotation.y = 0f;

                //check if walking
                if (IsWalking)
                {
                    //initialise variable
                    bool vMoveUP    = false;
                    bool vMoveRight = false;
                    bool vMoveLeft  = false;
                    bool vMoveDown  = false;

                    if (IsPlayer)
                    {
                        if (Input.GetAxis("Vertical") > 0 && !Input.GetButtonUp("Vertical"))
                        {
                            vMoveUP = true;
                        }
                        if (Input.GetAxis("Vertical") < 0 && !Input.GetButtonUp("Vertical"))
                        {
                            vMoveDown = true;
                        }
                        if (Input.GetAxis("Horizontal") > 0 && !Input.GetButtonUp("Horizontal"))
                        {
                            vMoveRight = true;
                        }
                        if (Input.GetAxis("Horizontal") < 0 && !Input.GetButtonUp("Horizontal"))
                        {
                            vMoveLeft = true;
                        }
                    }
                    else
                    {
                        //shorten variables
                        float vX = transform.position.x;
                        float vY = transform.position.y;

                        //NPC
                        if (vX <= vMainPlayer.transform.position.x /*&& vXValue*/)
                        {
                            vMoveRight = true;
                        }
                        else                         //if (vXValue)
                        {
                            vMoveLeft = true;
                        }

                        if (vY <= vMainPlayer.transform.position.y /*&& vYValue*/)
                        {
                            vMoveUP = true;
                        }
                        else                        // if (vYValue)
                        {
                            vMoveDown = true;
                        }
                    }

                    //check which position we are rotating
                    if (vMoveUP && vMoveRight)
                    {
                        CurWalkDirection = WalkDirection.RightUp;
                    }
                    else if (vMoveUP && vMoveLeft)
                    {
                        CurWalkDirection = WalkDirection.LeftUp;
                    }
                    else if (vMoveDown && vMoveLeft)
                    {
                        CurWalkDirection = WalkDirection.LeftDown;
                    }
                    else if (vMoveDown && vMoveRight)
                    {
                        CurWalkDirection = WalkDirection.RightDown;
                    }
                    else if (vMoveUP)
                    {
                        CurWalkDirection = WalkDirection.Up;
                    }
                    else if (vMoveLeft)
                    {
                        CurWalkDirection = WalkDirection.Left;
                    }
                    else if (vMoveDown)
                    {
                        CurWalkDirection = WalkDirection.Down;
                    }
                    else if (vMoveRight)
                    {
                        CurWalkDirection = WalkDirection.Right;
                    }

                    //calculate the new rotation
                    Vector3 temp = transform.rotation.eulerAngles;
                    temp.x             = 0f;
                    temp.y             = 0f;
                    temp.z             = GetWalkingRotation();
                    transform.rotation = Quaternion.Euler(temp);

                    //play leg animation backward
                    float vBackForward = 1;
                    if (vMoveDown)
                    {
                        vBackForward = -1;
                    }

                    //show the animation on the right direction
                    vLegAnimator.SetFloat("Direction", vBackForward);

                    //check where it's heading
                    Vector2 vDestination = new Vector2(0f, 1f) * WalkSpeed * Time.deltaTime;

                    //move the character in this direction
                    if (CanWalk)
                    {
                        transform.Translate(vDestination);
                    }
                }

                //rotate the body correctly
                //can only look at the player if he can see it
                if (CanRotateBody())
                {
                    if (IsPlayer)
                    {
                        vBodyObj.transform.rotation = Quaternion.Slerp(vBodyObj.transform.rotation, newRotation, 1000f);
                    }
                    else
                    {
                        vBodyObj.transform.rotation = Quaternion.Slerp(vBodyObj.transform.rotation, newRotation, Time.deltaTime);
                    }
                }

                vCamObj.transform.rotation = CamStartRotation;
            }
        }
    }