Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by jkm8 · May 14, 2016 at 01:02 PM · scripting problemweaponweapon system

My script doesnt work?

Hi

Im trying to add another weapon to my weapon script, but i just cant get it to work without errors.

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 
 public class PlayerWeapon {
 
     namespace Primary  
 
     public string name = "Rifle";
 
     public float damage = 10f;
     public float range = 200f;
     public float clip = 20f;
 
     public float fireRate = 4f;
 
     public GameObject GFX;
     
 
     namespace Secondary 
 
         public string name = "Pistol";
 
         public float damage = 40f;
         public float range = 50f;
         public float clip = 7f;
 
         public float fireRate = 10f;
 
     
 
 }

this script contains weapon data.

Comment
Add comment · Show 5
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 JedBeryll · May 14, 2016 at 01:40 PM 0
Share

What's that namespace Primary there? if you want this class to be in that namespace you have to either put it in that file or create a partial namespace. That line is not closed with anything so it will give errors. https://unity3d.com/learn/tutorials/modules/intermediate/scripting/namespaces

avatar image jkm8 JedBeryll · May 14, 2016 at 02:24 PM 0
Share

thanks now im using classes but my other script PlayerShoot.cs loads up with errors such as that it cant find the float that i referenced in the other script.

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof (Weapon$$anonymous$$ananger))]
 public class PlayerShoot : $$anonymous$$onoBehaviour {
 
 
 
 
 
 
 
 
 
     [SerializeField]
     private Camera cam;
 
     [SerializeField]
     private Layer$$anonymous$$ask mask;
 
 
     private Weapon$$anonymous$$ananger weapon$$anonymous$$ananger;
     private PlayerWeapon currentWeapon;
 
     void Start ()
     {
         if (cam == null)
         {
             Debug.LogError ("PlayerShoot: NO CA$$anonymous$$ERA REFERENCED!!!");
             this.enabled = false;
         }
         weapon$$anonymous$$ananger = GetComponent<Weapon$$anonymous$$ananger> ();
     }
 
     void Update () {
         currentWeapon = weapon$$anonymous$$ananger.GetCurrentWeapon ();
         if (currentWeapon.fireRate <= 0f)
         {
         if (Input.GetButtonDown ("Fire1")) {
             Shoot();
         }
     } else
     {
             if (Input.GetButtonDown ("Fire1")) {
                 InvokeRepeating ("Shoot", 0f, 1f / currentWeapon.fireRate);
             } else if (Input.GetButtonUp ("Fire1")) {
                 CancelInvoke ("Shoot");
             }
 
     }
     }
     void Shoot () {
         RaycastHit _hit;
         if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, currentWeapon.range, mask)) 
         {
             
             Debug.Log("Player just shoot at " + _hit.collider.name);
         }
     }
 }

avatar image JedBeryll JedBeryll · May 14, 2016 at 02:30 PM 0
Share

I'm not sure what you mean. A float is a value type not a reference type so you can't reference it. Please copy and paste some of those errors.

avatar image jkm8 JedBeryll · May 14, 2016 at 02:47 PM 0
Share

Assets/Entities/Weapon/PlayerShoot.cs(37,35): error CS1061: Type PlayerWeapon' does not contain a definition for fireRate' and no extension method fireRate' of type PlayerWeapon' could be found (are you missing a using directive or an assembly reference?) Assets/Entities/Weapon/PlayerShoot.cs(45,82): error CS1061: Type PlayerWeapon' does not contain a definition for fireRate' and no extension method fireRate' of type PlayerWeapon' could be found (are you missing a using directive or an assembly reference?) Assets/Entities/Weapon/PlayerShoot.cs(45,33): error CS1502: The best overloaded method match for UnityEngine.$$anonymous$$onoBehaviour.InvokeRepeating(string, float, float)' has some invalid arguments Assets/Entities/Weapon/PlayerShoot.cs(45,33): error CS1503: Argument #3' cannot convert object' expression to type float' Assets/Entities/Weapon/PlayerShoot.cs(54,108): error CS1061: Type PlayerWeapon' does not contain a definition for range' and no extension method range' of type PlayerWeapon' could be found (are you missing a using directive or an assembly reference?) Assets/Entities/Weapon/PlayerShoot.cs(54,29): error CS1502: The best overloaded method match for UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit, float, int)' has some invalid arguments Assets/Entities/Weapon/PlayerShoot.cs(54,29): error CS1503: Argument #4' cannot convert object' expression to type float'

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Having a few script errors that I ran into. 1 Answer

Having an issue where after I shoot a specific weapon, other weapons don't work as intended. 0 Answers

How to set gamobjects active on network? 0 Answers

Smooth aiming script don't work 0 Answers

2D Boomerang Style Weapon 1 Answer


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