How to load material onto sphere?
I have a cylinder, which when collides with a sphere, it creates another sphere in the scene through javascript.
I can add rigidbody component, but don't know how to change the material of the sphere that is generated...
 function OnCollisionEnter (col : Collision)
 {    
     var hoverForce = 150;
     if(col.gameObject.name == "Sphere")
     {    
            if (col.rigidbody) {
             col.rigidbody.AddForce(Vector3.up * hoverForce, ForceMode.Acceleration);
         }
         var sphereB : GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         sphereB.AddComponent(Rigidbody);
         sphereB.transform.position = Vector3(0, 5, 0);
         //GetComponent<Renderer>().material = ball_texture;
     }
     
 }
 
               Renderer.material seems to be depreciated, so how would I change it?
Thanks
Answer by hexagonius · Sep 13, 2015 at 01:00 PM
sphereB.GetComponent(Renderer).material
transform is the only shortcut left, all other components you need to get with GetComponent.
Hint: create a prefab with Rigidbody and the right material and spawn that instead.
Your answer
 
             Follow this Question
Related Questions
Material disappears after LoadScene 1 Answer
Render Pipeline Material Issue 1 Answer
Can someone change this array to use materials instead of textures 1 Answer
Keeping the size of a texture constant across different 3D gameobjects 0 Answers
What right way to SetTextureOffset of material which has dynamic count owners? 0 Answers