- Home /
Gun locator script isnt working
it says, that this script already has a definition for HitWeapons what am i doing wrong? please give the answer in C#
public GameObject SelectedWeapon;
public GameObject LastSelectedWeapon;
public GameObject GunHolder;
public int PickupDistance = 6;
public int O = 0;
private bool HitWeapons = false;
private Ray ray;
private RaycastHit hit;
// Use this for initialization
void Start ()
{
GunHolder = GameObject.FindWithTag("GunHolder");
}
// Update is called once per frame
void Update ()
{
ray = transform.camera.ScreenPointToRay (new Vector3(Screen.width / 2, Screen.height / 2, 0));
HitWeapons = true;
if(Physics.Raycast(ray, hit, PickupDistance))
{
if(hit.collider.gameObject.tag == "PickUp")
{
HitWeapons = false;
SelectedWeapon = hit.collider.gameObject;
isEquipped : boolean = CheckWeapons();
if(lastSelectedWeapon != selectedWeapon)
{
if(lastSelectedWeapon != null)
{
lastSelectedWeapon.GetComponent("SelectableWeapon").unSelect();
lastSelectedWeapon = selectedWeapon;
selectedWeapon.GetComponent("SelectableWeapon").select(isEquipped);
}
}
}
}
if(!HitWeapons)
{
if(lastSelectedWeapon != null)
{
lastSelectedWeapon.GetComponent("SelectableWeapon").unSelect();
selectedWeapon = null;
lastSelectedWeapon = null;
}
}
if(selectedWeapon && Input.GetButtonDown("Pickup"))
{
if(gunscript.takingOut)
{
return;
for(i = O ; i < playerWeapons.weapons.length; i++)
{
if(playerWeapons.weapons[i] == selectedWeapon.GetComponent(SelectableWeapon).weapon)
{
return;
}
playerWeapons.weapons[playerWeapons.selectedWeapon].gameObject.BroadcastMessage("deselectWeapon");
playerWeapons.weapons[playerWeapons.selectedWeapon] = selectedWeapon.GetComponent(SelectableWeapon).weapon;
playerWeapons.SelectWeapon(playerWeapons.selectedWeapon);
selectedWeapon.GetComponent("SelectableWeapon").select(true);
}
}
}
}
void CheckWeapons ()
{
for (i = O; i < playerWeapons.weapons.length; i++)
{
if (playerWeapons.weapons[i] == selectedWeapon.GetComponent("SelectableWeapon").weapon)
{
return true;
}
}
return false;
}
void HitWeapons ()
{
if(Physics.Raycast(ray, hit, PickupDistance))
{
if(hit.collider.gameObject.tag == "Weapons")
{
RayHitWeapon = true;
}
}
if(Physics.Raycast(ray, hit, PickupDistance))
{
if(!hit.collider.gameObject.tag == "Weapons")
{
RayHitWeapon = false;
}
}
}
Answer by Seth-Bergman · Jul 31, 2012 at 12:13 PM
I would say the problem is you have a boolean called HitWeapons, and then try to declare a method called HitWeapons as well
just give the function a unique name
EDIT:
public GameObject SelectedWeapon;
public GameObject LastSelectedWeapon;
public GameObject GunHolder;
public int PickupDistance = 6;
public int O = 0;
private bool hitWeapons = false;
private Ray ray;
private RaycastHit hit;
// Use this for initialization
void Start ()
{
GunHolder = GameObject.FindWithTag("GunHolder");
}
// Update is called once per frame
void Update ()
{
ray = transform.camera.ScreenPointToRay (new Vector3(Screen.width / 2, Screen.height / 2, 0));
hitWeapons = true;
if(Physics.Raycast(ray, hit, PickupDistance))
{
if(hit.collider.gameObject.tag == "PickUp")
{
hitWeapons = false;
SelectedWeapon = hit.collider.gameObject;
isEquipped : boolean = CheckWeapons();
if(lastSelectedWeapon != selectedWeapon)
{
if(lastSelectedWeapon != null)
{
lastSelectedWeapon.GetComponent("SelectableWeapon").unSelect();
lastSelectedWeapon = selectedWeapon;
selectedWeapon.GetComponent("SelectableWeapon").select(isEquipped);
}
}
}
}
if(!HitWeapons)
{
if(lastSelectedWeapon != null)
{
lastSelectedWeapon.GetComponent("SelectableWeapon").unSelect();
selectedWeapon = null;
lastSelectedWeapon = null;
}
}
if(selectedWeapon && Input.GetButtonDown("Pickup"))
{
if(gunscript.takingOut)
{
return;
for(i = O ; i < playerWeapons.weapons.length; i++)
{
if(playerWeapons.weapons[i] == selectedWeapon.GetComponent(SelectableWeapon).weapon)
{
return;
}
playerWeapons.weapons[playerWeapons.selectedWeapon].gameObject.BroadcastMessage("deselectWeapon");
playerWeapons.weapons[playerWeapons.selectedWeapon] = selectedWeapon.GetComponent(SelectableWeapon).weapon;
playerWeapons.SelectWeapon(playerWeapons.selectedWeapon);
selectedWeapon.GetComponent(SelectableWeapon).select(true); //(removed quotes)
}
}
}
}
void CheckWeapons ()
{
for (i = O; i < playerWeapons.weapons.length; i++)
{
if (playerWeapons.weapons[i] == selectedWeapon.GetComponent(SelectableWeapon).weapon)
return true;
}
}
return false;
}
void HitWeapons ()
{
if(Physics.Raycast(ray, hit, PickupDistance))
{
if(hit.collider.gameObject.tag == "Weapons")
{
RayHitWeapon = true;
}
}
if(Physics.Raycast(ray, hit, PickupDistance))
{
if(!hit.collider.gameObject.tag == "Weapons")
{
RayHitWeapon = false;
}
}
}
sorry didnt work, i get a ton more errors from talking out the void HitWeapon. mainly because i need to establish what a HitWeapon is, since i use it after
ray = transform.camera.ScreenPointToRay (new Vector3(Screen.width / 2, Screen.height / 2, 0));
and it is used here:
if(!HitWeapons)
you need to rename 1, and every instance where you reference it, rename it there too..
for example does
if(!HitWeapons)
refer to the boolean, or the function?
the compiler doesn't know
Your answer
Follow this Question
Related Questions
Gun Script 1 Answer
Reload clips on Gun-script not applied properly 1 Answer
Distribute terrain in zones 3 Answers
C# Parsing Error and Unexpected Symbol 1 Answer
RayCast Shooting not working 0 Answers