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 Bruno-Fludzinski · Jun 20, 2012 at 02:08 AM · bulletrespawn

Turret Bullets hurt me

Hi im using Tornado Twins' YouTube series on how to make a turret shoot at me using this script:

 var LookAtTarget : Transform;
 var damp : float = 6.0;
 var bullitPrefab : Transform;
 var shotTime: float = 0;
 var shotInterval: float = 2;
 var speed : float = 1000.0;
 
 function Update ()
 {
      if(LookAtTarget)
      {
           var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); 
           transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp); 
           if (Time.time > shotTime){ 
               Shoot();
               shotTime = Time.time + shotInterval;
           }
      }
 }
 
 function Shoot()
 {
      var bullit = Instantiate(bullitPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
      bullit.rigidbody.AddForce(transform.forward * speed);
 }

and it works great but i want when the bullet hits me, for it to hurt me, or say if 5 bullets hit me, i respawn. Any idea how to do this? Thanks so much!

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

2 Replies

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

Answer by djm · Jun 20, 2012 at 03:32 AM

Try adding a health script to your player. When the player gets hit you take damage until you reach zero and at that point you will respawn.

 var health : float = 100.0;
 var damageRate:float = 3;
 var startHealth:float;
 
 function Awake()
 {
     startHealth = health;
 }
 
 function Update () 
 {
     if (health < 0) 
     {
         Reset();
     }
 }
 
 function OnGUI () {
     GUI.backgroundColor = Color.yellow;
     GUI.Label(Rect(300,10, 150, 30), "Player Health");
     GUI.Box (Rect (300,40,150,30), "" + Mathf.Round(health));
       
 }
 
 function Reset(){
     
     transform.position = Vector3(0,0,0);
         
     health = startHealth;
     print("your dead");
 
 }
 
 
 function OnTriggerEnter (theCollider : Collider) {
      
      if(theCollider.tag == "enemy" ) 
      {
          health -=damageRate * Time.deltaTime;
      }    
 }
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 Bruno-Fludzinski · Jun 20, 2012 at 03:55 AM 0
Share

thank you!

avatar image Bruno-Fludzinski · Jun 20, 2012 at 04:13 AM 0
Share

I can't add tags in my Unity, its a bug i think is there another way?

avatar image JohnD2012 · Jun 20, 2012 at 05:42 AM 0
Share

@djm , for that health bar script do i need to head it with #pragma strict? :p

avatar image djm · Jun 20, 2012 at 05:48 AM 0
Share

Hi JohnD, Not that I'm aware of, I'm testing it out on a game now and it works as expected, just need to add a tag for the "enemy".

But if there is a reason to disable the dynamic scripting, I guess you could try adding #pragma strict at the top. ;-)

avatar image
0

Answer by lunaDirus · Jun 20, 2012 at 08:01 AM

i had trouble adding tags too. the problem is that the text field is the same color as the background of the tag manager alt text

when you open the tag manager you have two columns the number and the tag name. place your mouse over the word water in the second column and move down until it is in line with user layer 8 in the first column if you there you will be able to type in a text field and make your own layer.

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 Bruno-Fludzinski · Jun 20, 2012 at 12:49 PM 0
Share

i can write the tags they just dont show up

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

FPS spawn bullet 0 Answers

Enemy respawn once hit by bullet please help 1 Answer

Bullet Spawn 3 Answers

Character Re-spawn Problem 0 Answers

Bullet Ricochet Errors 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