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 tim-wheeler · Oct 23, 2012 at 05:41 PM · guitexture

Swapping multipul textures on mouse over using raycast

hi Im trying to swap a texture that is always present in the middle of the screen. so that if it is over nothing it always shows the tooth, if it is over a person collider tagged "switch" the speech texture comes up and the tooth texture disappears, this i achieved.

Then i added another texture "pals" to swap when it was over a collider with the tag "pals" then the pals texture swapped ok, but the switch texture stopped working as soon as I added

`else if(hit.collider.gameObject.tag == "pals"){ currentChar1 = hit.collider.gameObject; leaf1 = true; }`.

can anyone tell me where i have gone wrong please.

 private var currentChar1 : GameObject;
 private var currentChar2 : GameObject;
 
 var mouser : boolean;
 var leaf1 : boolean;
 
 var tooth : GUITexture;
 var speech : GUITexture;
 var leaf : GUITexture;
 
 function Update() {
 var hit : RaycastHit;
     if (Physics.Raycast(transform.position, transform.forward, hit , 15)){
 
     
     if(hit.collider.gameObject.tag == "switch"){
         currentChar2 = hit.collider.gameObject;
         mouser = true;
 
     }
     
     else if(hit.collider.gameObject.tag == "pals"){
         currentChar1 = hit.collider.gameObject;
         leaf1 = true;
     }
     
     else {
         mouser = false;
         leaf1 = false;
         }
     }
 
     textureSwapper();
 }
 
 
 function textureSwapper(){
     if (mouser == true){
         tooth.enabled=false;
         speech.enabled=true;
     }
 
     if (leaf1 == true){
         tooth.enabled=false;
         leaf.enabled=true;
     }
 
     else {
         tooth.enabled=true;
         speech.enabled=false;
         leaf.enabled=false;
     }
 
 }
 
Comment
Add comment · Show 1
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 DaveA · Oct 23, 2012 at 05:54 PM 0
Share

Define 'stopped working' what's not working, how does it behave?

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Oct 23, 2012 at 05:54 PM

I would guess you need to set mouse = false in that new clause.

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 tim-wheeler · Oct 26, 2012 at 09:34 AM

I went through and made sure that they variables and ifs were balanced with true and false. I am having the same issue. The speech texture used to swap with the tooth texture until I added the leaf texture "else if" statement

Now the leaf texture is swapping with the tooth texture But the speech texture isn't swapping with the tooth texture

I hope that makes sense.

I have also seen that the variable is switching on and off as it should just the texture isn't showing. I have also paused the player and switched on and off the texture to make sure it is visible at the correct coordinates and it is showing ok.


 var mouser : boolean;
 var leaf1 : boolean;
 
 var tooth : GUITexture;
 var speech : GUITexture;
 var leaf : GUITexture;
 
 function Update() {
 var hit : RaycastHit;
     if (Physics.Raycast(transform.position, transform.forward, hit , 15)){
 
     
     if(hit.collider.gameObject.tag == "switch"){
         currentChar2 = hit.collider.gameObject;
         mouser = true;
         leaf1 = false;
 
     }
     
     else if(hit.collider.gameObject.tag == "pals"){
         currentChar1 = hit.collider.gameObject;
         leaf1 = true;
         mouser = false;
     }
     
     else {
         mouser = false;
         leaf1 = false;
         }
     }
 
     textureSwapper();
 }
 
 
 function textureSwapper(){
     if (mouser == true){
         tooth.enabled=false;
         speech.enabled=true;
         leaf.enabled=false;
     }
 
     if (leaf1 == true){
         tooth.enabled=false;
         speech.enabled=false;
         leaf.enabled=true;
     }
 
     else {
         tooth.enabled=true;
         speech.enabled=false;
         leaf.enabled=false;
     }
 
 }
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 tim-wheeler · Nov 06, 2012 at 06:57 PM

Two weeks later and I still havent figured this out.Is there anyone out there at all that could help its doing my head in.....

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 tim-wheeler · Nov 06, 2012 at 06:57 PM

ok I figured it out :)

 private var currentChar1 : GameObject;
 private var currentChar2 : GameObject;
 
 var mouser : boolean;
 var leaf1 : boolean;
 var tooth1 : boolean;
 
 var tooth : GUITexture;
 var speech : GUITexture;
 var leaf : GUITexture;
 
 function Update() {
 var hit : RaycastHit;
     if (Physics.Raycast(transform.position, transform.forward, hit , 30)){
 
     
     if(hit.collider.gameObject.tag == "switch"){
         currentChar = hit.collider.gameObject;
         mouser = true;
         leaf1 = false;
         tooth1 = false;
     }
     
     else if(hit.collider.gameObject.tag == "pals"){
         currentChar = hit.collider.gameObject;
         leaf1 = true;
         mouser = false;
         tooth1 = false;
     }
     
     else {
         mouser = false;
         leaf1 = false;
         tooth1 = true;
         }
     }
 
     textureSwapper();
 }
 
 
 function textureSwapper(){
     if (mouser == true){
         tooth.enabled=false;
         speech.enabled=true;
         leaf.enabled=false;
     }
 
     if (leaf1 == true){
         tooth.enabled=false;
         speech.enabled=false;
         leaf.enabled=true;
     }
     if (tooth1 == true) {
         tooth.enabled=true;
         speech.enabled=false;
         leaf.enabled=false;
     
     }
 
 }
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

10 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

Related Questions

OnGui Function help 1 Answer

Repeat fade in and out 1 Answer

Understanding GUISkin/GUIStyle BackgroundImage and Border 2 Answers

Aspect Ratio changes GUI Location Code in CSHARP 1 Answer

GUI button doesn't appear on Android 0 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