1
\$\begingroup\$

I have a player game-object with a script Player. In the Player script I have a public properties weapons.

I want to have to just drag in this properties a script/prefabs. And the Player script must can get the properties of the weapons selected.

For example: imagine, we have two weapons, one is a pistol with 5 attack power, the other is a knife with 7 attack power.

Now I want to set pistol in the Player script. enter image description here

What should I drag here ? A game-object with a weapon script ? Or a weapons script who instantiate a weapon ? Or maybe an another solution ...

The idea is to be able to create easily some weapons without scripting more. Just place a sprite, and modify some properties.

\$\endgroup\$
1
\$\begingroup\$

You can always just stuff all weapons in one big list and access them with an index.

[System.Serializable]
public class Weapon
{
    public string name;
    public float damage;
}

[System.Serializable]
public class Player
{
    public Weapon[] weapons;
    public int currentWeapon;
}

public Player player;

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.