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 zolon · Oct 26, 2014 at 08:55 PM · crashclassenum

Unity Crashes when i attach script to object

So whenever i attach this script Unity stops responding Im not sure if because of my script but here is my script anyways:

 public class weapon extends overWorld
 {
 public var ammo : int;
 public var damage : int;
 public var numberOfBullets : int;
 public var firetype : int;
 public var range :int;
 public var weaponType : weaponTypes;
 
 }
 
 public function weapon()
 {
 ammo = 0;
 damage = 0;
 numberOfBullets = 0;
 firetype = 0;
 range = 0;
 weaponType = weaponTypes.pistol;
 }
 
 public function weapon(amm : int, dmg : int, numOfBullets : int, rateOfFire : int, rng : int, wpnType : weaponTypes)
 {
 ammo = amm;
 damage = dmg;
 numberOfBullets = numOfBullets;
 firetype = rateOfFire;
 range = rng;
 weaponType = wpnType;
 }
 
 public enum weaponTypes
 {
 sword,
 pistol,
 shotgun,
 machinegun,
 semiauto,
 sniper,
 }
 
 public var sniper : weapon = new weapon(5, 5, 5, 1, 5, weaponTypes.sniper);




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 Landern · Oct 26, 2014 at 08:57 PM

You need to keep the scope of the class together, you defined the class and the constructors in different scopes. I'm also not sure if overWorld extends/inherits/derives from MonoBehaviour. It should to be attached to a game object in the inspector

 public class weapon extends overWorld
 {
     public var ammo : int;
     public var damage : int;
     public var numberOfBullets : int;
     public var firetype : int;
     public var range :int;
     public var weaponType : weaponTypes;
 
     // Parameterless constructor of class weapon
     public function weapon()
     {
         ammo = 0;
         damage = 0;
         numberOfBullets = 0;
         firetype = 0;
         range = 0;
         weaponType = weaponTypes.pistol;
     }
 
     // Parameterized constructor of class weapon
     public function weapon(amm : int, dmg : int, numOfBullets : int, rateOfFire : int, rng : int, wpnType : weaponTypes)
     {
         ammo = amm;
         damage = dmg;
         numberOfBullets = numOfBullets;
         firetype = rateOfFire;
         range = rng;
         weaponType = wpnType;
     }
 
     // I'm assuming the scope of this, you will again access outside of the cass with weapson.weapsonTypes.sword for example
     public enum weaponTypes
     {
         sword,
         pistol,
         shotgun,
         machinegun,
         semiauto,
         sniper,
     }
 }
 
 public var sniper : weapon = new weapon(5, 5, 5, 1, 5, weaponTypes.sniper);
 


Comment
Add comment · Show 1 · 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 zolon · Oct 27, 2014 at 01:37 AM 0
Share

Thanks but i also found out i was missing:

 public class weapon{

After:

  public class weapon extends overWorld
  {

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Overriding an inherited Enum? 1 Answer

Help integrating a category system 0 Answers

PropertyDrawer: Enum to select extended class 0 Answers

How do I create a bunch of player abilities, with their own properties? 2 Answers

Changing class variables 2 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