I want to be able to change the material of specific tagged objects; For instance, I have activated a palette of colours and textures that only work on objects with the tag "wood".
I don't want to expose the objects in the inspector, just need to find them by tag:
#pragma strict
var myObject : GameObject;
var texture1 : Texture2D;
function Update ()
{
if( Input.GetMouseButtonDown(0) )
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100))
if (hit.collider.tag == "wood")
{
myObject.renderer.material.mainTexture = texture1;
}
}
}
If I go with
hit.renderer.material.mainTexture.... and so on, I get this error:
Assets/Paintbrush.js(17,37): BCE0019: 'renderer' is not a member of 'UnityEngine.RaycastHit'.
↧