Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
AshwinTheGammer

How to rotate the target of shooting range.

Question

I want to rotate the target from 0 to 180 when it health becomes 0 and after 5 seconds back to 0. I tried taking hints from Armed unity kits but it didn't help me.  Below is code. 

 

 

public float CurrentHealth;

public float max health = 100;

 

Void Start () {

CurrentHealth = maxhealth;

}

 

Public void killer (float damage) {

 

CurrentHealth -= damage;

If(CurrentHealth == 0)

//rotate the target to 0 to 180

}

 

yield return new WaitForSeconds(5f) ;

 

StartCorotouine (down());

 

IENumerator down () {

 

// back to 0 rotation

}

 

 

 

Please login or register to see this quote.

 

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 1

Place the script on the object which will rotate. Since the script will rotate the object from it's pivot (generally it's in the center of the object which is not what you want here) you should create an empty object (rotate that empty object) and put the actual target model inside the empty object.

 

I'm not a FPS kit expert so I have no idea where you should call this from (probably somewhere in the gun manager or a bullet script, where the hit registration happens) but if you find it just do:

Please login or register to see this code. Please login or register to see this code.

 

Edited by UnityGamesRoland

Share this post


Link to post
Share on other sites

  • 1
Please login or register to see this quote.

from anywhere.
Do you have weapon script?

 

In this script you still need:

Please login or register to see this code.

 

Share this post


Link to post
Share on other sites
  • 0

Or you can save yourself from all the coding and just animate it on impact.

 

void ApplyDamage(float amount)

{

if(animation.IsPlaying(downAndStationaryAnim)) return;

animation.CrossFade(downAndStationaryAnimName);

while(animation.IsPlaying(downAndStationaryAnim)) yield;

animation.CrossFade(upAnimName);

}

 

is just a basic example

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...