Question by
rolandnakhoul · Jul 06, 2017 at 07:39 AM ·
c#scripting problemeditorvrscripting beginner
Tetxure swap using HTC controllers
Hello, i have a script that swap any texture just by mouse clicking on the mesh. can anyone help me editing this script so i can swap textures using HTC vive controllers trigger. thank you
THE SCRIPT:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TextureSwap : MonoBehaviour { public Material[] materials; public Renderer Rend;
private int index = 1;
// Use this for initialization
void Start () {
Rend = GetComponent<Renderer> ();
Rend.enabled = true;
}
void OnMouseDown()
{
if (materials.Length == 0)
return;
if (Input.GetMouseButtonDown (0)) {
index += 1;
if (index == materials.Length + 1)
index = 1;
print (index);
Rend.sharedMaterial = materials [index - 1];
}
}
}
Comment