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 DanProd · Feb 21, 2019 at 01:58 PM · scripting problemtriggerailoophealth

Another function for activating a different script

So I have this problem, basically my aihealth script relies on triggers and i want to do the same with the player detection but then they would share different triggers for different purposes..Any fix?

Comment
Add comment · Show 7
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 xxmariofer · Feb 21, 2019 at 02:59 PM 0
Share

what do you mean by different triggers? you can compare the tag of the collider you are colliding with and use if statements for doing one logic or another, if this is your question.

avatar image DanProd xxmariofer · Feb 22, 2019 at 09:47 AM 0
Share

Ok Thank you well here is the code:

{ public int Pain = 2; public float hitLast = 0; public float hitDelay = 1;

  void OnTriggerStay(Collider other)
  {
      if (other.gameObject.tag == "Player")
      {
          if (Time.time - hitLast < hitDelay)
              return;
 
          Vector3 damageDirection = other.transform.position - transform.position;
          damageDirection = damageDirection.normalized;
          FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
 
          hitLast = Time.time;
      }
  }
 

}

And the problem is I wanted to make a trigger function, where, if the player ever enters it the target would be given and therefore chase the player BUT the problem is i have another script attached to the ai which receives damage from the player using the trigger function, so it would be a mess right? the ai would receive damage from the player without even getting close to the ai

here is the damage code:

{ public int Pain = 2; public float hitLast = 0; public float hitDelay = 1;

  void OnTriggerStay(Collider other)
  {
      if (other.gameObject.tag == "Player")
      {
          if (Time.time - hitLast < hitDelay)
              return;
 
          Vector3 damageDirection = other.transform.position - transform.position;
          damageDirection = damageDirection.normalized;
          FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
 
          hitLast = Time.time;
      }
  }
 

}

avatar image xxmariofer DanProd · Feb 22, 2019 at 09:53 AM 0
Share

hello, you can create an empty gameobject child of the player withanother tag something like PlayerRange and inside the ontriggerstay compare if the trigger you are collising is the player or the playerrange. you can make the triggerrange collider bigger for that porpuse.

avatar image zereda-games · Feb 21, 2019 at 03:08 PM 0
Share

Got any examples of your issue, images, code. more details

avatar image tormentoarmagedoom · Feb 21, 2019 at 05:56 PM 0
Share

Good day.

You are not giving information. We dont understand what you say. Please explain, give code, give examples...

avatar image DanProd tormentoarmagedoom · Feb 22, 2019 at 09:46 AM 0
Share

Ok Thank you well here is the code:

 {
     public int Pain = 2;
     public float hitLast = 0;
     public float hitDelay = 1;
 
     void OnTriggerStay(Collider other)
     {
         if (other.gameObject.tag == "Player")
         {
             if (Time.time - hitLast < hitDelay)
                 return;
 
             Vector3 damageDirection = other.transform.position - transform.position;
             damageDirection = damageDirection.normalized;
             FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
 
             hitLast = Time.time;
         }
     }
 
 }

And the problem is I wanted to make a trigger function, where, if the player ever enters it the target would be given and therefore chase the player BUT the problem is i have another script attached to the ai which receives damage from the player using the trigger function, so it would be a mess right? the ai would receive damage from the player without even getting close to the ai

here is the damage code:

 {
     public int Pain = 2;
     public float hitLast = 0;
     public float hitDelay = 1;
 
     void OnTriggerStay(Collider other)
     {
         if (other.gameObject.tag == "Player")
         {
             if (Time.time - hitLast < hitDelay)
                 return;
 
             Vector3 damageDirection = other.transform.position - transform.position;
             damageDirection = damageDirection.normalized;
             FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
 
             hitLast = Time.time;
         }
     }
 
 }
 



avatar image DanProd tormentoarmagedoom · Feb 22, 2019 at 09:47 AM 0
Share

Ok Thank you well here is the code:

{ public int Pain = 2; public float hitLast = 0; public float hitDelay = 1;

  void OnTriggerStay(Collider other)
  {
      if (other.gameObject.tag == "Player")
      {
          if (Time.time - hitLast < hitDelay)
              return;
 
          Vector3 damageDirection = other.transform.position - transform.position;
          damageDirection = damageDirection.normalized;
          FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
 
          hitLast = Time.time;
      }
  }
 

}

And the problem is I wanted to make a trigger function, where, if the player ever enters it the target would be given and therefore chase the player BUT the problem is i have another script attached to the ai which receives damage from the player using the trigger function, so it would be a mess right? the ai would receive damage from the player without even getting close to the ai

here is the damage code:

{ public int Pain = 2; public float hitLast = 0; public float hitDelay = 1;

  void OnTriggerStay(Collider other)
  {
      if (other.gameObject.tag == "Player")
      {
          if (Time.time - hitLast < hitDelay)
              return;
 
          Vector3 damageDirection = other.transform.position - transform.position;
          damageDirection = damageDirection.normalized;
          FindObjectOfType<PlayerHealth>().DamagePlayer(Pain, damageDirection);
 
          hitLast = Time.time;
      }
  }
 

}

0 Replies

· Add your reply
  • Sort: 

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

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

Script is only working on original object 2 Answers

Ontrigger not working with npc 0 Answers

Animator trigger keeps retriggering. 0 Answers

Enemy evade sight of player 1 Answer

Enemy doesn't avoid static objects 2 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