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 geryc123 · Feb 01, 2014 at 01:47 PM · enemy

This Script don't work, Why? / Life players

I have this script:

 #pragma strict
 
 var lives = 3;
 var livesTexture : Texture2D[];
 var livesTextureSize = 30;
  
 function OnGUI ()
 {
     var livesTextureRect = Rect(10,5,livesTextureSize,livesTextureSize);
     for (var i : int = 0; i < lives; i++)
     {
         GUI.DrawTexture(livesTextureRect,livesTexture[i], ScaleMode.ScaleToFit, true, 0.0f);
         livesTextureRect.x += livesTextureSize + 10;
     }
 }
  
 
 
  
 
 function OnTriggerEnter (myTrigger : Collider) {
  if(myTrigger.gameObject.name == "Enemy")
 
      {
      
     
     print("work?");
         if (lives-1 >= 0)
             livesTexture[lives-1] = null;
 
        WaitForSeconds(2);
         
          Invoke("life", 2);
         
     }
 } 
 
 
 function life()
 {
 
 
 
  Invoke("life2", 2);
 
  
  
 lives --;
 
 
 
 
 }
 
 
 function life2()
 
 {
 
  Invoke("life3", 2);
 
 lives --;
 
 
 
 }
 
 
 function life3()
 
 {
 
 
 lives --;
 
 
  
  print("YOU DEAD");
  
  
  }

When I enter a trigger for tag "enemy" in general does not detect it. No shows "print (" work ");" What is wrong?

Script added to the First person controller.

The enemy has the tag "Enemy"

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
0

Answer by asafsitner · Feb 01, 2014 at 01:48 PM

You're not actually checking the tag, instead you're checking the object's name

if(myTrigger.gameObject.name == "Enemy")

should be

if(myTrigger.gameObject.tag == "Enemy")

Comment
Add comment · Show 4 · 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 geryc123 · Feb 01, 2014 at 02:21 PM 0
Share

Actually :O Thank You!

avatar image geryc123 · Feb 01, 2014 at 02:35 PM 0
Share

And how to modify the script? that only when the player is in the "trigger" fetch life, now is so that when player out from "trigger" further takes life.

avatar image DynamicPrgm · Feb 01, 2014 at 02:49 PM 0
Share

This is called when a trigger is exited:

 void OnTriggerExit (Collider other) {
      //etc
 }

If that is what you mean :P

avatar image geryc123 · Feb 01, 2014 at 03:08 PM 0
Share

When a player enters the trigger with the tag "Enemy" take life. I want to stop "to take life" when player comes out of the trigger. :P

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

20 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

Related Questions

How do I make an enemy? 1 Answer

Why is my enemy stopping before it reaches the player? 1 Answer

Taking a hit 3 Answers

Spawning enemy mobs .......... Instantiate woe ? 2 Answers

Any one have an AI spaceship script 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