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 LPGaming-Company · Jan 21, 2013 at 07:05 PM · c#gameobjectenumbasic

NPC Class looking for help

So, I'm trying to set up a basic NPC... all it has for stats is current and max health, but I'm not using the scene editor for this project, it's all in the scripting. So I'm curious as to the most efficient way to do this.

 using UnityEngine;
 using System.Collections;
 
 public class BasicEnemy {
     GameObject[] basicEnemy;
     
     void Start() {
         basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
         basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
         basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
         basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
         basicEnemy += GameObject.CreatePrimitive(PrimitiveType.Cube);
         basicEnemy[0].tag = "Mob";
         basicEnemy[1].tag = "Mob";
         basicEnemy[2].tag = "Mob";
         basicEnemy[3].tag = "Mob";
         basicEnemy[4].tag = "Mob";
         
     }
 }
     
 public enum BasicEnemyStats {
     currentHealth,
     maxHealth
 }


my goal is to get a group of enemies that all have the currentHealth and maxHealth stats, while doing this I will use the array to combat NPC's of a certain type until there are none left. Thus winning the game.

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
1

Answer by coastwise · Jan 21, 2013 at 08:54 PM

I understand and appreciate that you want to create your mob through scripting, thats awesome! I would recommend however, first creating a single instance of your mob NPC in the editor and testing it out. Attach your custom Mob Monobehaviour script (which has currentHealth and maxHealth public members) to this object, its mesh (or cube), etc, etc. When it's all nice and working how you like, turn it into a prefab.

A prefab is like a cookie cutter for game objects. You make one, then you can reuse it to create as many copies (clones) as you like in a scene (through scripting).

So you would then make a MobSpawner script (inheriting from Monobehaviour as well) that would instantiate as many copies as are needed. You'd drop this spawner in your scene and let the havoc unfold.

I apologise if this answer is too high-level, please let me know if you could use further clarification.

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 LPGaming-Company · Jan 21, 2013 at 09:22 PM 0
Share

Thanks for your reply, although I don't want to use the editor. I've done this before, and I know how to do it that way. I know what Instantiating is aswell, although none of my scripts inherit from $$anonymous$$onoBehavior besides for my Application$$anonymous$$anager script, which runs all of my other scripts through instances, I'm trying to do this without using the editor in any way shape or form. Considering I'm using C# Instantiating seems to not be working as it should, calling for different parameters than the scripting references are asking for. I've honestly yet to get it to work properly.

Thanks for your answer... Also, I don't know what I was thinking with the above script... O_O, looking at it again... I'm like "What... the hell."

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making changes to a terrian in game 1 Answer

C# Check If Scripted Gameobject goes Past Variable Gameobject 0 Answers

C# Make Child Not Animate Looped Animation 1 Answer

C# GameObjectList not Setting Parent 0 Answers

Multiple Cars not working 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