x


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;
 }
 }
 }
more ▼

asked Jul 31 '12 at 11:30 AM

djfunkey gravatar image

djfunkey
23 2 5 9

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
 }
 }
 }
more ▼

answered Jul 31 '12 at 12:13 PM

Seth Bergman gravatar image

Seth Bergman
7k 10 16 28

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)

Jul 31 '12 at 12:20 PM djfunkey

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

Jul 31 '12 at 12:43 PM Seth Bergman
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4376
x3420
x1581
x461

asked: Jul 31 '12 at 11:30 AM

Seen: 237 times

Last Updated: Jul 31 '12 at 12:49 PM