- Home /
Select colour then change texture
I'm looking to do a colouring book type scene where the user clicks the colour they want, then when they click a part of the model it colours it with that selected colour. I've seen this script:
var a : gameobject;
a.renderer.material.color = Color.blue;
Which I can link to a Raycast script but I'm not sure how to go about selecting the colour and then implementing it when the model is clicked.
I also found the following script:
#pragma strict
private var ray : Ray;
private var hit : RaycastHit;
private var selectedColour : GameObject;
function Start () {
}
function Update () {
if(Input.GetMouseButtonDown(0)){
ray=Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,hit)){
if(hit.transform.name == "CubeRed"){
selectedColour = GameObject.Find("Cube");
}
if(hit.transform.name == "Cube"){
selectedColour.renderer.material.color = Color.red;
}
}
}
}
This script finds the cube when the colour button is clicked, then applies the selected colour to the cube when the cube is clicked. A little closer but still some major problems.
Firstly, when I add more colours to the script, it doesn't function, only takes into account the last colour specified, despite being on separate buttons.
Secondly, I don't want the script to look for a certain object, I want it to be applied to any of the objects I click after that.
Any ideas? Thanks in advance