- Home /
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;
     }
 
 }
 
Define 'stopped working' what's not working, how does it behave?
Answer by DaveA · Oct 23, 2012 at 05:54 PM
I would guess you need to set mouse = false in that new clause.
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;
     }
 
 }
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.....
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;
     
     }
 
 }
Your answer
 
 
             Follow this Question
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
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                