Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Pigpork · Dec 25, 2018 at 08:18 PM · variableenemycustomizationcustomizevariable-definition

How to make a customizable variable in this script?

How do I make the damage to the player a customizable script as I want all melee enemies to use the same script but with different damage and it would take too much resources to duplicate and lightly modify the script for each enemy type.

Here is the script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Mushroom_attack_script : MonoBehaviour { public Sprite sprite_attack; public SpriteRenderer spriteRenderer; public Sprite sprite_idle;

 void OnTriggerStay(Collider other)
 {
     //It will check for the name of the GameObject that had enter inside the enemy trigger
     if (other.gameObject.name == "FPSController")
     {
         HealthBarScript.health -= 0.0075f;
     }

  

} void OnTriggerEnter(Collider other) { //It will check for the name of the GameObject that had enter inside the enemy trigger if (other.gameObject.name == "FPSController") { spriteRenderer.sprite = sprite_attack;// Change sprite }

 }

 void OnTriggerExit(Collider other)
 {
     //It will check for the name of the GameObject that had enter inside the enemy trigger
     if (other.gameObject.name == "FPSController")
     {
         spriteRenderer.sprite = sprite_idle;// Change sprite
     }

 }

}

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 Vega4Life · Dec 25, 2018 at 10:07 PM

Is this what you are looking for?


 using UnityEngine;
 
     public class Mushroom_attack_script : MonoBehaviour
     {
         public float damageAmount = 0.0075f;   // Set this in the inspector for each melee guy
         public Sprite sprite_attack;
         public SpriteRenderer spriteRenderer;
         public Sprite sprite_idle;
 
 
         void OnTriggerStay(Collider other)
         {
             //It will check for the name of the GameObject that had enter inside the enemy trigger
             if (other.gameObject.name == "FPSController")
             {
                 HealthBarScript.health -= damageAmount;  // Take out the literal and put in our variable.
             }
 
         }
     }


When you attach your script to each enemy, you go into the inspector and set the amount of damage you want each one to do in the Damage Amount variable.


Comment
Add comment · Show 2 · 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 Pigpork · Dec 26, 2018 at 07:35 PM 0
Share

Thank you so much for helping as I couldnt find the answer anywhere else for hours.

avatar image Vega4Life Pigpork · Dec 26, 2018 at 09:03 PM 0
Share

No problem. Good luck!

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

168 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How should i approach character customization? 1 Answer

How to change the shape of gameObjects 2 Answers

How to update your position your every frame 1 Answer

How can I activate and deactivate an enemy on player proximity 0 Answers

Double Trouble: Slider Mesh appearance and Bone Physics 0 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