Which one is better, in terms of

Hello. I Just came out from learning Java, not much experienced but I think I can make it, and I want to make an amazing Game using Unity, but I don’t know some facts of unity since I just started 4 days ago and all what I know its because I am watching YouTube videos, asking friends and searching in google.

Now, let’s say:
My game has various enemies, bosses, items and different characters to play with, every single of this will make a different thing. For example, if you take Item1, you can jump higher, if you take Item2, its a sword you can use just once and deal an enemy certain amout of damage. Enemy1 has different attacks as Enemy2, Enemy1 can Jump and make like exploding attacks, Enemy2 can’t jump and just make simple attacks and so with Enemy3,4,5,6,7,8. The idea here is to make a lot of different enemies (I have 21 planned this moment), A LOT of different items (I have 400+ in my mind) and some bosses (I dont have any)

My Question is:
How can I assing SpriteRenderers, or any component without making it public and selecting it in the Inspector?

Do I need to create a single prefab for each item, each playable character, enemy, and boss, then, make a lot of repeated variables, for example Health and MovementSpeed,
OR

For example:
Every character and enemies have its own attacks and variables, such as health, mana, dodge chance, critical chances, etc. and items too.
Can I create, lets call them Catalogs, codes called “CharacterAttacks”, “EnemyAttacks”, “ItemEffects”, “PlayerStats”, access to its methods, for example:

//Catalog of enemies attacks in "EnemyAttacks"
public void doAttack(int AttackID){ //If an enemy will attack, do so by calling this method from "Enemy.cs"
  //todo process of the attack goes in here
}
//example of a script that ALL enemies will have
float Health = 100;
float MovementSpeed = 1;
float JumpHeight = 3;
float AttackSpeed = 1;
SpriteRenderer Sprite;
int EnemyID;

void Start(){
  EnemyID = Random.range(0,100);
  switch(EnemyID)
  case 0:
  //How can I obtain an sprite in my asset folder without making public SpriteRenderer Sprite and selecting it in the inspector?
  break;
   default:
    //Same question here
    break;
}

void Update(){
//MovementSystem
}

void OnTriggerEnter2D(Collider collider){
  if (collider.gameObject.tag == "PlayerHitBox"){
  //How can I access to the script "EnemyAttacks" if I dont make it component of any of my gameObjects in the scene?
  }
}

and access to them every time I use attack1, every time I need to get the effect of an item, etc. instead of making prefabs and scripts for each one?
Or even go for OOP?

Which one is more practical and proffesional?
Which one is more efficient in performance?
Which one is better for multiplayer?

Another question is:
If I use a gameObject which is the player and have as component “PlayerControl” but there is just one script “PlayerStats” that have all the stats, for example JumpHeight , is this practical for local cooperative or even online multiplayer?

Thanks for reading this and I hope that you have a good day!
Please if you know the answers of my questions, feel free to post them and receive my thanks!

You ask a lot of very broad questions and that’s a fairly ambitious first project. Have you gone through the tutorials provided by Unity yet? See the Learn link at the top of the page. A lot of the basic how-to questions you’re asking (such as Instantiating prefabs, finding and referencing scripts and objects in the scene, or using Resources.Load) are explained there.

At this stage of experience, I’d recommend avoiding multiplayer altogether. That dramatically complicates the problems you need to understand and solve.

In terms of varying how your items and enemies behave, you probably want to define interfaces so that the scripts which need to trigger their actions or effects have a consistent way to interact with them. To give you a rough idea of what that might look like for the various items you want to create:

// this would be defined in a separate c# file
public interface IItemEffects
{
    void ExecuteEffect(Player player, Enemy target);
}

// this is a MonoBehaviour so you can drop it on the prefab that represents your "Jump Higher" item
public class Item_JumpHigher : MonoBehaviour, IItemEffects
{
    public void ExecuteEffect(Player player, Enemy target)
    {
        // in this case the target doesn't matter since this item makes the player jump higher
        player.currentJumpHeight = player.jumpHeight * 2; // just making it up...
    }
}

public class Item_Sword : MonoBehaviour, IItemEffects
{
    public void ExecuteEffect(Player player, Enemy target)
    {
        target.TakeDamage(Random.Range(10,21));
    }
}

// some other process (not shown here) would have previously assigned a Player object and maybe an Enemy
// assume the Player class (not shown here) has an IItemEffects property called equippedItem
public class PlayerControl : MonoBehaviour
{
    public Player player;
    public Enemy target;

    void Update()
    {
        if(Input.GetButtonDown(0) && player.equippedItem != null)
        {
            // this way the controller doesn't care what the item actually is or does
            equippedItem.ExecuteEffect(player, target);
        }
    }
}
1 Like

As @MV10 already said, maybe you should spend some weeks learning how to use Unity and coding:

:slight_smile:

Yeah, you are right, I have been so ignorant and trying to skip stuff just to try to go ahead but the real thing is that I am going wrong. I will look up at unity tutorials.

Anyway, thank you for your reply, @MV10 !