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
3
Question by SrBilyon · Oct 03, 2010 at 09:19 PM · animationtextureswaptoonshadingblink

"Blinking Eyes" Texture Animations

I am making a game with toon-shaded graphics. The main character object has multiple textures and one of those is his eyes. I was trying to figure out how can I "animate" them though code? I was thinking that maybe I could make a script that has a timer and it would quickly swap the eye texture with one that looks like a blinking animation, that or use a .gif.

I also have other textures that gives his eyes expressions, but my only program is that I don't know how to code a texture swap/animation, especially for things like cut scenes that have separate animations that the in-game animations.

Also, the character model was made in blender, so if anyone could tell me how to change the texture via the blender Action Editor/IPO Curve Editor, that would be helpful.

Comment
Add comment · Show 2
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 sirdavid23 · Jun 19, 2012 at 05:45 PM 0
Share

How did your game came along? do you have a tumblr? or video?

avatar image Bunny83 · Jun 19, 2012 at 05:48 PM 0
Share

@sirdavid23: This is not a forum to chit-chat. Even when you have a question to a post from someone else, use a comment and not an answer. This is a Q&A site and ment as knowledge database.

I've converted your answer into a comment.

Btw. This question is almost 2 years old...

1 Reply

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

Answer by Adam Rademacher · Oct 03, 2010 at 10:26 PM

If I understand your question right, you want to swap out textures on a timer to make the character 'blink'. Try something like this (javascript) -- Assuming that your eyes are on a different material than the rest of your character.

var normalEyes : Texture2D; //normal (open) eye texture var blinkyEyes : Texture2D; //blinking eye texture var eyeMaterial : Material; //eye material on player var eyeTimer : float; //time to keep eyes open var blinkTimer : float; //time to keep eyes closed var blinking : bool; //is the character currently blinking? private var currTime : float;//current timer var randomFactor : float; //a random factor to make it a little more interesting

function Start() { currTime = eyeTimer + Random.value * randomFactor; //establish current timer as open eyes eyeMaterial.mainTexture = normalEyes; //set eye texture to open blinking = false; //we are not blinking }

function Update() { if(currTime > 0.0f) //if the timer is greater than 0 { currTime -= Time.deltaTime; //subtract time } else //if the timer is up { if(blinking) //if the character is blinking { currTime = eyeTimer + (Random.value randomFactor); //reset the timer to the open time + a random value eyeMaterial.mainTexture = normalEyes; // set the texture to open eyes blinking = false; //we are no longer blinking } else //if the character is not blinking { currTime = blinkTimer + (Random.value randomFactor); //reset the timer to blinking time + a random value eyeMaterial.mainTexture = blinkyEyes; //set the texture to blinky eyes blinking = true; //we are now blinking } } }

You may find you want a different random factor for blinking and not blinking, but that should be simple enough to do (or you may find you don't want a random factor at all).

Comment
Add comment · Show 3 · 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 SrBilyon · Oct 03, 2010 at 11:00 PM 0
Share

Thanks for the quick response! This is exactly what i was looking for!

avatar image SrBilyon · Dec 05, 2010 at 03:56 AM 0
Share

For some reason, the textures won't swap anymore (i just started a new project) where should this script be placed?

avatar image Adam Rademacher · Dec 07, 2010 at 07:12 PM 0
Share

It should go wherever you want it to. You'll have to re-assign the textures and material as well as reset the timers in the inspector.

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

2 People are following this question.

avatar image avatar image

Related Questions

Custom Pivot Points in Sprite Editor 1 Answer

Unity4.5 AnimationCurve - Is the property "_MainTex.rotation" valid ? 0 Answers

Animating Texture? 2 Answers

Pixel Color Issue 1 Answer

Set the procedural color texture script to a set pattern? 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