Quantcast
Viewing all articles
Browse latest Browse all 62

Change materials from arrawy with tag check

Basically the model in the scene has to be simply setup - each part that has a material(s) is tagged and when I click on it it should cycle through the available materials set in the inspector. It works with one so far but I have some issues with more than one; Now regardless where I click it changes only the first object in the list (walls) var matArrayWalls : Material[]; var walls : GameObject; var roof : GameObject; var matArrayRoofs : Material[]; private var indexWalls : int; private var indexRoofs : int; function Update () { if (Input.GetMouseButtonDown(0)){ var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit : RaycastHit; indexWalls++; indexWalls = indexWalls % matArrayWalls.Length; indexRoofs++; indexRoofs = indexRoofs % matArrayRoofs.Length; if (Physics.Raycast(ray, hit)){ if(hit.collider.tag == "walls") { walls.renderer.material = matArrayWalls[indexWalls]; } if(hit.collider.tag == "roof") { roof.renderer.material = matArrayRoofs[indexRoofs]; } } } }

Viewing all articles
Browse latest Browse all 62

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>