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 Bentoon · Jun 20, 2014 at 05:38 AM · collisiontextbooleanfadein

triggering 3DText by collision

Hello Y'all

here is a Text Game:

I have 3DText sandwiched between 2 Planes (1&2)

I made it into a prefab and will line a few of them up like dominos for a Camera to move through on a path ...So words appear as you scroll forward along the Z Axis Triggered by colliding with the Planes (fade in & out the Text based on a boolean)

but I am having problems with the semantics of the .js code that I am attaching to the Prefab

 #pragma strict
 
 
 // var to access Text mesh
 var myText : TextMesh;
 //switch text Mesh on and off
 var mySwitch : boolean = false;
 
 
 
 function Start () {
 }
 
 // Fade in myText
 function fadeIn () {
 Fade.use.Alpha(myText.renderer.material, 0.0, 1.0, 1.0, EaseType.In);
 }
 
 // Fade out myText
 function fadeOut () {
 Fade.use.Alpha(myText.renderer.material, 1.0, 0.0, 1.0, EaseType.Out);
 }
 
 
 
 //when Camera(or FPC) collides with Plane_1
 // Fade in or out depending on switch
 function onCollision ("plane_1") {
     if mySwitch = false {
         fadeIn;
         mySwitch = true;
     }
     else mySwitch = true {
         fadeOut;
         mySwitch = false;
     }
 }    
     
 //when Camera(or FPC) collides with Plane_2
 // Fade in or out depending on switch    
 function onCollision ("plane_2") {
     if mySwitch = false {
         fadeIn;
         mySwitch = true;
     }
     else mySwitch = true {
         fadeOut;
         mySwitch = false; 
     }
 }    
 

Any help is greatly appreciated !!

~be

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
Best Answer

Answer by Bentoon · Jun 20, 2014 at 09:54 PM

Hey Landem Thank you So much for your time, my original way of thinking was problematic

I found and manipulated a script that allows me only to work with the text based on Position

See below:

 #pragma strict
  
     var fadeIn : boolean;
     var fadeOut : boolean;
     var fadeSpeed : float = 0.01;
     var minAlpha : float = 0.0;
     var maxAlpha : float = 1.0;
     var minDistance = 3;
     var target : Transform;
     var myTransform : Transform;
  
     function Awake()
     {
     myTransform = transform;
 }
  
     function Start()
     {
  
     target = GameObject.FindWithTag("Player").transform;
  
     }
  
     function Update()
     {
  
     if(fadeIn && !fadeOut)
     FadeIn ();
  
     if(fadeOut && !fadeIn)
     FadeOut ();
  
     if(renderer.material.color.a <= minAlpha)
     {
     fadeOut = false;
     if(Vector3.Distance(myTransform.position, target.position) < minDistance)
     {
     fadeIn = true;
     }
     }
  
     if(renderer.material.color.a >= maxAlpha)
     {
     fadeIn = false;
     if(Vector3.Distance(myTransform.position, target.position) > minDistance)
     {
     fadeOut = true;
     }
     }
     }
  
     function FadeIn()
     {
     renderer.material.color.a += fadeSpeed;
     }
  
     function FadeOut()
     {
     renderer.material.color.a -= fadeSpeed;
     }
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
0

Answer by Landern · Jun 20, 2014 at 12:27 PM

Add a collider to the 3d text.

Check for collision, in the case below it's OnCollisionEnter, but you can check for other states.

 #pragma strict
  
 // var to access Text mesh
 var myText : TextMesh;
 //switch text Mesh on and off
 var mySwitch : boolean = false;
  
 function Start () {
 }
  
 // Fade in myText
 function fadeIn () {
     Fade.use.Alpha(myText.renderer.material, 0.0, 1.0, 1.0, EaseType.In);
 }
  
 // Fade out myText
 function fadeOut () {
     Fade.use.Alpha(myText.renderer.material, 1.0, 0.0, 1.0, EaseType.Out);
 }
  
 function OnCollisionEnter(collision : Collision) {
     if (collision.name = "plane_2" || collision.name == "plane_1") {
         if (mySwitch == false) { // Could also evaluate !mySwitch
             fadeIn();
             mySwitch = true;
         } else { 
             fadeOut();
             mySwitch = false; 
         }
     }
 }   


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 Bentoon · Jun 20, 2014 at 01:50 PM 0
Share

Thank you, i like the compressed code, but I can't run it - it generates a bunch of errors to console!

: o

see Picture

screen shot 2014-06-20 at 9.47.45 am.png (51.8 kB)
avatar image Landern · Jun 20, 2014 at 01:53 PM 0
Share

Ahh, i didn't catch you wrote your if statements incorrectly, fixed, damnit and forgot your parenthesis when calling fadeIn and fadeOut...

avatar image Bentoon · Jun 20, 2014 at 07:41 PM 0
Share

Lander Thank you

It's getting closer, but there are still problems with line 22 that's not letting me compile:

 if (collision.name = "plane_2" || collision.name == "plane_1") {


see Pict

Thanks so much for your time!

~be

screen shot 2014-06-20 at 3.37.23 pm.png (25.1 kB)

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

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

Related Questions

Changing localScale on Collision2D 2 Answers

Changing Boolean on collision 0 Answers

i have 2 assets , i want to make a text appear after a collision between them (and end the game if that is possible) , how can i do that ? 1 Answer

Problem with OnTriggerStay2D function 2 Answers

OnTriggerEnter Multiple Collisions Activating. I tried many variations, Please help (Java) 3 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