Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by djfunkey · Jul 31, 2012 at 11:30 AM · c#raycastgun

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;
  }
  }
  }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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;
  }
  }
  }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image djfunkey · Jul 31, 2012 at 12:20 PM 0
Share

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)

avatar image Seth-Bergman · Jul 31, 2012 at 12:43 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges