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
3
Question by Kith · Mar 24, 2010 at 04:48 PM · enemyhitflash

Making a model flash a certain color when shot

So I have a Player character that shoots a prefab projectile at an enemy prefab. What would be the best way to have that prefab flash a certain color once the projectile and enemy collide. It seems like it would be a simple solution, but I'm not sure how to implement it.

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

3 Replies

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

Answer by Eric5h5 · Mar 24, 2010 at 05:50 PM

Change the renderer.material.color briefly; something like

OnCollisionEnter () {
   renderer.material.color = collideColor;
   yield WaitForSeconds(.5);
   renderer.material.color = normalColor;
}

This works fine even if the prefab does have a texture. The entire texture will be tinted by the color of the material.

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 Kith · Mar 24, 2010 at 07:48 PM 0
Share

Thanks again :-)

avatar image
4

Answer by IRobb · Jul 07, 2014 at 01:39 AM

I have made this for my game. It's a coroutine called from OnTriggerEnter. MainRenderer is the renderer associated with the object. It disables the material, then it changes color to white. This code is from a bigger class where color and material are saved before.

 IEnumerator collideFlash() {
     Material m = this.mainRenderer.material;
     Color32 c = this.mainRenderer.material.color;

     this.mainRenderer.material = null;
     this.mainRenderer.material.color = Color.white;
     yield return new WaitForSeconds(0.1f);
     this.mainRenderer.material = m;
     this.mainRenderer.material.color = c;            
 }
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
avatar image
1

Answer by Binxalot · Jan 23, 2014 at 07:51 PM

quick note for anyone using this. The code above works for the diffuse shader, not the mobile diffuse shader, also, it affects the material across all models in your scene so you'll want to be careful if you have a bunch of clones running around, those will blink as well unless you change it so they have unique materials assigned. This works perfectly though.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Make enemy Flash when Hit 3 Answers

How can I load a scene when the enemy hits the player? 5 Answers

Blood on weapon. 1 Answer

Raycast gun 2 Answers

Show Enemy Name On UI Canvas? 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