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 /
avatar image
0
Question by connorwforman · Dec 18, 2017 at 11:14 PM · scripting problem

What is a target component?

I am watching a Brackey's tutorial and he wrote this line of code:

 Target target = //then he checked if it had a target component


then he said something about "target components". What are those and how do I add those? They don't seem to exist in Unity C#.

Comment
Add comment · Show 5
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 Hellium · Dec 19, 2017 at 08:56 AM 1
Share

Please, provide the full context, at least the link to the tutorial you are mentionning.

avatar image connorwforman Hellium · Dec 19, 2017 at 02:04 PM 0
Share

https://www.youtube.com/watch?v=THnivyG0$$anonymous$$vo

(Somewhere around the 5:30-6:00 $$anonymous$$ part is where it starts)

He wrote this enemy script:

 public class health = 50f; 
 
 public void TakeDamage (float amount) {
          health -= amount; 
          if (health <= 0)
          {
                   Die(); 
          }
 void Die () {
        Destroy(gameObject); 
 }
 
 }


Then he did this to the shoot script:

 //existing
 
 public GameObject fpsCam; 
 public float amount = 100f; 
 
 void Shoot () {
       RaycastHit hit; 
       if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
 {
 Debug.Log(hit.transform.range); 
 Target target = hit.transform.GetComponent<Target>(); 
 }
 }
avatar image fafase · Dec 19, 2017 at 10:29 AM 0
Share

This is most likely an Editor script. ¨

https://docs.unity3d.com/ScriptReference/Editor-target.html

Target is $$anonymous$$onoBehaviour script to be affected by the Editor script.

The $$anonymous$$B does not know about the Editor but the Editor needs to get info about the $$anonymous$$B so it can change what is rendered.

avatar image connorwforman fafase · Dec 19, 2017 at 01:50 PM 0
Share

It says to make a public Object target; line in the variable section. Is that what I am supposed to do for the Target target = hit.transform.GetComponent<Target>(); Where would I put the public Object target;line, would I make a separate enemy script?

@fafase

avatar image fafase connorwforman · Dec 19, 2017 at 02:00 PM 0
Share

can't say. I would guess if the tutorial says so then that is what you should do.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by KittenSnipes · Dec 19, 2017 at 02:30 PM

@connorwforman

Ok the answer is right in your face. Nice try anyway. This script:

         public float health = 50f; 
         public void TakeDamage(float amount)
         {
             health -= amount;
             if (health <= 0)
             {
                 Die();
             }
         }
     
         void Die()
         {
             Destroy(gameObject);
         }

Has a title above it. Looks like this: public class Target : MonoBehavior

The name after class in Brackey's videos is what he is calling because it is a script you add to all things that are damageable. So whatever your script's name is will be what you put.

So say I have:

 public class HealthManager : MonoBehavior {
     public int health = 100;
 
     public void changeHealth(int amount) {
         health += amount;
     }
 }

In my other script I would reference it like:

 public class Gun : MonoBehavior
 {
     public int damageAmount = -10;
     HealthManager health;
 
     void Shoot() {
         //Shoot bullet
         if (//Object is hit) {
             health = hit.GetComponent<HealthManager>();
             health.changeHealth(damageAmount);
         }
     }
 }

So it is as simple as that. Hopefully this helps.

Comment
Add comment · 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

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

125 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

Related Questions

Animating key on AnimationCurve in real time 0 Answers

Where should I call Physics2D.Raycast ? 0 Answers

i have two errors ; expected,i got two errr 1 Answer

Door smoothly opens to the side - Problem 3 Answers

Help with OnTriggerEnter 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