Hi,
I have asked this question in answers section without much help there. I really need to understand how it works.
Hi all I am trying to learn my way through Unity and have setup a scene
I have A as prefab (custom) and B (sphere) of which A has 2 sphere gameobject as child. When the scene starts A is hidden via renderer.
My aim is when B is touched A should get activated and when B is touched again A should get deactivated. I have manage to achieve the first part ( Touch B to activate A), but cannot get A to deactivate again.
Please help, the script follows
using UnityEngine;
using System.Collections;
public class touchtest1 : MonoBehaviour {
public Renderer A_mesh;
public GameObject A_prefab;
void Start() {
A_mesh.GetComponent<Renderer>().enabled = false;
}
void Update () {
RaycastHit hit = new RaycastHit();
for (int i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch (i).phase == TouchPhase.Began) {
Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (i).position);
if (Physics.Raycast (ray, out hit)) {
if (hit.collider.name == "B") {
Debug.Log ("hit B!!!!!");
A_mesh.enabled = true;
A_prefab.SetActive (true);
}
}
}
}
}
}