- Home /
This question was
closed Jan 13 at 09:49 PM by
Wesley21spelde for the following reason:
fixed it my self
Question by
Wesley21spelde · Jan 13 at 08:14 PM ·
intweaponswitchother scriptby
Change Weapon by its Script int
hey guys i wanted to ask how i can Set a Weapon on in this script by setting the selectWeapon int to a 1or 2 or 3 i tried getting this ....
if (selectWeapon >= transform.childCount - 1)
selectWeapon = 0;
else
selectWeapon++;
in to my
public void Weapon_1_Selected(){
}
this is for my savegame manager. all the parts work this script shares its selected weapon int to my loadSave Script and i can load it back in to the selecweapon int works fine but i cant get it woking that it will go to weapon 0 if the selectweapon int is 0. i even tried this
void Selectweapon()
{
} here is the script...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponSwitchMouseWheel : MonoBehaviour
{
public Animator anim;
public GameObject[] Weapons;
public GameObject Player;
public GameObject CurrentWeapon;
public int selectWeapon = 0;
public bool isWeapon_1 = false;
public bool isWeapon_2 = false;
public bool isWeapon_3 = false;
void Start()
{
//anim = GetComponentInChildren<Animator>();
Selectweapon();
Player = GameObject.FindGameObjectWithTag("Player");
Player.SendMessage("Weapon_1True");
Debug.Log("selected weapon = 0 ");
}
public void Weapon_1_Selected()
{
if(isWeapon_1 == true)
{
// do nothing
}
else
{
isWeapon_1 = true;
isWeapon_2 = false;
isWeapon_3 = false;
selectWeapon = 0;
}
}
public void Weapon_2_Selected()
{
if(isWeapon_2 == true)
{
// Do nothing
}
else
{
isWeapon_1 = false;
isWeapon_2 = true;
isWeapon_3 = false;
selectWeapon = 1;
}
}
void Update()
{
int previousSelectedWeapon = selectWeapon;
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
{
CurrentWeapon.GetComponent<Animator>().enabled = false;
anim.SetBool("WeaponSwitcherAnim", true);
anim.SetBool("WeaponSwitcherAnimIlde", false);
if (selectWeapon >= transform.childCount - 1)
selectWeapon = 0;
else
selectWeapon++;
// Weapon_1_Selected();
}
if (Input.GetAxis("Mouse ScrollWheel") < 0f)
{
CurrentWeapon.GetComponent<Animator>().enabled = false;
anim.SetBool("WeaponSwitcherAnim", true);
anim.SetBool("WeaponSwitcherAnimIlde", false);
if (selectWeapon <= 0)
selectWeapon = transform.childCount -1;
else
selectWeapon--;
//Weapon_2_Selected();
}
if (previousSelectedWeapon != selectWeapon)
{
StartCoroutine(WaitForAnimationTime());
CurrentWeapon.GetComponent<Animator>().enabled = true;
}
if(selectWeapon == 0)
{
Player = GameObject.FindGameObjectWithTag("Player");
Player.SendMessage("Weapon_1True");
isWeapon_1 = true;
isWeapon_2 = false;
isWeapon_3 = false;
}
if (selectWeapon == 1)
{
Player = GameObject.FindGameObjectWithTag("Player");
Player.SendMessage("Weapon_2True");
isWeapon_1 = false;
isWeapon_2 = true;
isWeapon_3 = false;
}
}
IEnumerator WaitForAnimationTime()
{
yield return new WaitForSeconds(0.75f);
Selectweapon();
anim.SetBool("WeaponSwitcherAnim", false);
anim.SetBool("WeaponSwitcherAnimIlde", true);
}
void Selectweapon()
{
int i = 0;
foreach (Transform weapon in transform)
{
if (i == selectWeapon)
weapon.gameObject.SetActive(true);
else
weapon.gameObject.SetActive(false);
i++;
}
}
}
Comment
Follow this Question
Related Questions
Cycling through enum with key press 1 Answer
Anyone help with my switch statement? 0 Answers
Weapon Switch Animations 1 Answer
Int Switch always chooses same value 1 Answer
Controlling Weapons With MouseWheel 2 Answers