- Home /
Crosshair Progress Circle in VR Based Application
Hi, I am trying to make a 360 Degree Image GoogleCardoard app in unity3d.
I created a Sphere and made 5 material and applied 360 degree image in material. I am swapping material by Raycast and its working but the problem is when crosshair touches the arrow (applied raycast on arrow and crosshair to swap material) the material is changing very fast. i applied a radial progress bar but its not working. What I want is crosshair loading animation everytime when material change
here is my c# code
using UnityEngine;
using System.Collections;
public class next : MonoBehaviour {
public CardboardHead head;
public Material[] myMaterials = new Material[6];
int maxMaterials;
int arrayPos = 0;
public GameObject Sphere;
public int timeToCompleteLoading = 3;
void Start ()
{
head = Camera.main.GetComponent<StereoController> ().Head;
maxMaterials = myMaterials.Length-1;
}
public void ToggleVRMode()
{
Cardboard.SDK.VRModeEnabled = !Cardboard.SDK.VRModeEnabled;
}
IEnumerator RadialProgress(float time)
{
yield return new WaitForSeconds(time);
float rate = 1 / time;
float i = 0;
while (i < 1)
{
i += Time.deltaTime * rate;
gameObject.renderer.material.SetFloat("_Progress", i);
}
}
void Update ()
{
RaycastHit hit;
Collider collider = GetComponent<Collider> ();
if (collider) {
bool isLookAt = collider.Raycast (head.Gaze, out hit, 6.0f);
if (isLookAt == true) {
if (collider.gameObject.tag == "next") {
StartCoroutine (RadialProgress (timeToCompleteLoading));
if (arrayPos == maxMaterials){
arrayPos = 0;
}else{
arrayPos++;
Sphere.renderer.material = myMaterials [arrayPos];
}
}
}
}
}
}
Please Help. Thanks
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612053725im_/https://answers.unity.com/themes/thub/images/avi.jpg)