- Home /
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
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);
Thanks but i also found out i was missing:
public class weapon{
After:
public class weapon extends overWorld
{
Your answer
Follow this Question
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