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 XecKieN · Dec 15, 2014 at 01:26 PM · c#raycastpink

Raycast pink material

Hi all, i'm a beginner with Unity and I have a problem with RayCast. My objective is to make a chess board, and to change the color of the square I click on, the selection is correct (the correct square change color), but it become pink. Here is my full code (the raycast is at line 31) :

 using UnityEngine;
 using System.Collections;
 
 public class Modele : MonoBehaviour {
     
     public Material mat;
     
     // Use this for initialization
     void Start () {
         GameObject caseC, caseF;
         caseC = GameObject.Find("CaseC");
         caseF = GameObject.Find("CaseF");
         GameObject tmp = null;
         for(int i=0 ; i<8 ; i++) {
             for(int j=0 ; j<8 ; j++) {
                 if(i%2 == j%2)
                     tmp = (GameObject)Instantiate(caseC);
                 else
                     tmp = (GameObject)Instantiate(caseF);
                 tmp.transform.position = new Vector3(i,0,j);
             }
         }
         Destroy(caseC);
         Destroy(caseF);
         select = null;
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetMouseButtonDown(0)){ // if left button pressed...
             Ray ray = camera.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             if (Physics.Raycast(ray, out hit)){
                 hit.collider.gameObject.renderer.material = mat;
             }
         }
     }
 }
 

http://image.noelshack.com/fichiers/2014/51/1418648844-sans-titre.jpg

As you can see in the screen, my public variable is set. I also tried to do it with the texture directly (with a Texture variable and with the material.mainTexture attribute), but it make the area white.

An other small question would be : what is the better way to create 64 squares, I don't think my method is really good...

Sorry for my English, It's not my native language, and thank you for your time.

Comment
Add comment · Show 11
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 HarshadK · Dec 15, 2014 at 01:18 PM 0
Share

Pink meterial is a shader issue. Try to check if your material assigned to variable 'mat' has a proper shader to it.

avatar image MrSoad · Dec 15, 2014 at 01:18 PM 0
Share

Have you tested the $$anonymous$$aterial that you have assigned to the "mat" var outside of your code. When something goes pink it is often the result of a shader problem on the $$anonymous$$aterial. $$anonymous$$ake sure this $$anonymous$$aterial is fully working and let us know, thanks.

avatar image XecKieN · Dec 15, 2014 at 01:22 PM 0
Share

The shader I use is the default Diffuse, and yes I tried the material : on my picture the light squares does use the same one. And i noticed that when I click on a square and then explore its properties in the 3D view it doesn't have any material.

EDIT : And if I does the same with the texture modification I have the same problem : the texture isn't set anymore in a new instance of my material.

avatar image HarshadK · Dec 15, 2014 at 01:38 PM 0
Share

Just check if your 'mat' is null before assigning it to the game object and put a debug if it is null.

avatar image MrSoad · Dec 15, 2014 at 02:13 PM 1
Share

Convert your comment to an answer @taxvi Then he can accept it as such :)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by taxvi · Dec 15, 2014 at 01:51 PM

select an object that the script is attached to, then in the inspector scroll down to the script and see THERE if the material is assigned. your screenshot does not tell weather the mat is assigned or not

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Bottom area of a 3D model? Raycast? 1 Answer

How to get the distance between two objects in feet/meter? 1 Answer

Mouse Click + Raycast + Colliders 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