Hi Guys,
I’m having trouble changing the material on children inside a prefab via a raycast hit…
To set the scene I have a city that I want to be able to click on blocks and bring up a list of some sort, all in AR.
I’ve got everything working for the prototype aside from the “highlight”/change material.
I want to be able to highlight/change material of the block I click on/raycast hit, as well as bring up the UI details about the block/plot/gameobject.
Eventually I want to be able to bring in those details via a CSV file and update via the cloud but need the prototype up and running first.
I’ve got the material changing but it effects the first material slot of everything…
Eventually I want to be able to do more things with the children but will settle for understanding my problem a bit better…
As always I appreciate your time and any and all help is much appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
public class IsClicked : MonoBehaviour {
public CanvasGroup ItemCanvas;
public Renderer rend;
public Material StartColour;
public Material childColour;
public List<Transform> objects;
public List<Transform> childObjects;
public Material Glow;
List <Material> childColours;
List<Renderer> childRenderers;
Renderer childRenderer;
void Start ()
{
rend = GetComponent<Renderer>();
childColours = new List<Material>();
childRenderers = new List<Renderer>();
childRenderer = GetComponent<Renderer> ();
StartColour = childRenderer.material;
for (int i = 0; i < transform.childCount; ++i) {
childRenderers.Add (transform.GetChild (i).GetComponent<Renderer> ());
childColours.Add (childRenderers *.material);*
-
}*
-
}*
-
void Update () {*
-
if (Input.GetMouseButtonDown (0)) {*
-
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);*
-
RaycastHit hit;*
-
if (Physics.Raycast (ray, out hit, 1000)) {*
-
ItemCanvas.interactable = true;*
-
ItemCanvas.blocksRaycasts = true;*
-
ItemCanvas.alpha = 1;*
-
childRenderer.material = Glow;*
-
for (int i = 0; i < childRenderers.Count; ++i)*
_ childRenderers .material = Glow;_
* if (hit.collider.tag == “plot_01”) {
Debug.Log (“plot_01”);
_ }_
if (hit.collider.tag == “plot_02”) {
Debug.Log (“plot_02”);
_ }_
if (hit.collider.tag == “plot_03”) {
Debug.Log (“plot_03”);
_ }_
_ }*_
* else{*
* Debug.Log (“you clicked on nothing”);*
* ItemCanvas.interactable = false;*
* ItemCanvas.blocksRaycasts = false;*
* ItemCanvas.alpha = 0;*
* childRenderer.material = StartColour;*
* for(int i = 0; i < childRenderers.Count; ++i)*
childRenderers_.material = childColours*;
}*_
* }*
* }*
}