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
1
Question by Tekksin · Dec 25, 2013 at 08:23 AM · collisionmaterialfunctionlerp

Where can a Lerp be used?

I'm trying to make a lerp for one of my enemies once its trigger is activated. So I have to put it in the function that dictates that, which is a collision function.

Does lerp only work in function Update? Or do I have something wrong?

Here are the relevant parts of my script:

 var thePrefab: GameObject;
 var enemyActive : boolean = true;
 var jelReg : Material;
 var jelShock : Material;
 var duration = 60.0;
 
 private var coin : GameObject;
 private var player : PlayerScript;
 
 function Start(){
 player = GameObject.FindWithTag("Player").GetComponent(PlayerScript);
 renderer.material = jelReg;
 }
 
 function Update () {
 }
 
 
 function OnCollisionEnter(theCollision : Collision){
     if(player.Diamond == true){
         Destroy(gameObject.transform.root.gameObject);
         coin = Instantiate(thePrefab, transform.position, Quaternion.identity);
     }
     if(player.Diamond == false){
         if(theCollision.gameObject.tag == "Player"){
             yield WaitForSeconds(2);
             gameObject.collider.isTrigger = true;
             enemyActive = true;



             var lerp : float = Mathf.PingPong (Time.time, duration) / duration;
             renderer.material.Lerp (jelReg, jelShock, lerp);




             yield WaitForSeconds(3);
             gameObject.collider.isTrigger = false;
             renderer.material = jelReg;
             enemyActive = false;
         }
     }
 }

it's probably something small, or that lerps just can't be used outside of the update function. Whatever the case, please help!

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
0

Answer by Entrio · Dec 25, 2013 at 08:48 AM

OnCollisionEnter gets called only, you guessed it, on collision enter. it gets executed once.

lerping is a process over time, so you will need a way to constantly update the lerp over time. An update or fixed update is the perfect place to do this.

have a read here, it describes it a little bit better.

Comment
Add comment · Show 2 · 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 Tekksin · Dec 25, 2013 at 09:20 PM 0
Share

I can't seem to find useful information in that link. There's a download for a program, but I'm not about to risk that... anyways, ok, so it cannot be executed in a collisionenter function. Does that mean I have to create a new function with the lerp information in it, and then link it that way? I tried that and it didn't work...

How do I make it so that a lerp can be used once a box collider triggers a trigger to be true?

avatar image tanoshimi · Dec 25, 2013 at 10:03 PM 1
Share

use a coroutine. http://docs.unity3d.com/Documentation/$$anonymous$$anual/Coroutines.html

avatar image
0

Answer by Indie_Solo · Jun 25, 2014 at 01:31 PM

have you tried on collision enter, then on collision stay. [http://docs.unity3d.com/ScriptReference/Collider.OnCollisionStay.html][1]

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

21 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 avatar image

Related Questions

"Unknown resolve error" 2 Answers

Error with function OnTriggerXXX 1 Answer

Character Controller and moving/lerping object collisions 0 Answers

Problem with lerping several objects to positions. 2 Answers

Material doesn't have a color property '_Color' 4 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