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 IndieScapeGames · Mar 20, 2012 at 07:29 PM · colliderontriggerentermaintexture

Change Main Texture on Collider not Collidee

This has me stumped. I'm able to successfully change the texture of an entity, lets say for this example a cube, when my Player collides with the cube. However, I want to change the texture for my Player, not the cube. I think what is throwing me off, is that the texture is attached to a child of the overall Player entity.

Here is my code for changing the Cube's texture.

 using UnityEngine;
 using System.Collections;
 
 public class changeTex : MonoBehaviour {
     public Texture texturea;
     public Texture textureb;
     public Collider other;
     // Use this for initialization
     void Start () {
         renderer.material.mainTexture = texturea;
     }
     
    
     void OnTriggerEnter(Collider other) {
         this.other = other;
         //other.tag="Player";
         if(other.tag!="Player") {
             print ("nice try");
         } else {
             renderer.material.mainTexture = textureb;
         }
     }
 }


You can see that the Player has to have a tag of "Player" for it to work. Now, my code where instead of changing the Cube's texture, you change the Player's texture.

 using UnityEngine;
 using System.Collections;
 
 public class changeToHelmColor : MonoBehaviour {
     public Texture normTexture;
     public Texture changeTexture;
     public Collider other;
     
     // Use this for initialization
     void Start () {
         renderer.material.mainTexture = normTexture;
     }
     
     // Update is called once per frame
     void Update () {
         
     }
     
     void OnTriggerEnter(Collider other) {
         this.other = other;
         
         if(other.tag != "Helm") {
             print("Nice try");
         } else {
             renderer.material.mainTexture = changeTexture;
         }
     }
 }


From what you see, upon colliding with the cube, it will change the texture. I have selected the Cube's tag as Helm, because I want this script to change the player's helm texture.

What is happening though, is that upon loading, it immediately prints "Nice try", and doesn't update when I do collide with the cube.

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 IndieScapeGames · Mar 21, 2012 at 12:33 AM 0
Share

Is it possible to modify Unity so it doesn't create a Skinned $$anonymous$$esh Render? I'm pretty sure that's what's throwing it off.

avatar image IndieScapeGames · Mar 21, 2012 at 12:41 AM 0
Share

Just this code with a Cube with a two temporary textures. It changes as its supposed to which is reason for me to believe that it is in fact a Skinned $$anonymous$$esh Renderer bug.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Mar 20, 2012 at 07:33 PM

Set a breakpoint there and see what other.tag really is. Obviously it's not Helm. You would have to either put this script on the part of the player that needs to change (unless the entire player only has one mesh), or you would have this script find the sub-part and get its renderer and change it.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can't add colliding game objects to a list. 1 Answer

Access other collider without use of Trigger collider. 1 Answer

MonoBehaviour.OnTriggerX vs Collider.OnTriggerX 1 Answer

OnTriggerEnter not being called with multiple colliders 1 Answer

Best practice for checking which object has collided. 2 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