Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Touch Questions from a beginner

Discussion in 'Getting Started' started by Dragon-Bubble, Oct 4, 2015.

?

how to solve this questiion?

Poll closed Oct 19, 2015.
  1. how to design the codes?

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. Dragon-Bubble

    Dragon-Bubble

    Joined:
    Aug 5, 2015
    Posts:
    2
    If I want to use the collision body at the same time touching him with a counter plus one , and with two button controls to make one gameobject hided and the others showed , how can I do ? Here is what I currently write code


    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;

    public class Touch : MonoBehaviour {

    public GameObject Previous;
    public GameObject Next;

    public GameObject fur1;
    public GameObject fur2;
    public GameObject fur3;

    int count = 0;

    SphereCollider InvisibleButton1;
    Vector3 ButtonPosition1;
    float ButtonRadius1;

    SphereCollider InvisibleButton2;
    Vector3 ButtonPosition2;
    float ButtonRadius2;


    void Start()
    {
    InvisibleButton1 = this.GetComponent<SphereCollider>();
    ButtonPosition1 = InvisibleButton1.center;
    ButtonRadius1 = InvisibleButton1.radius;
    }
    void Update()
    {
    if (count % 3 == 0)
    {
    fur1.SetActive(true);
    fur2.SetActive(false);
    fur3.SetActive(false);
    }
    if (count % 3 == 1)
    {
    fur1.SetActive(false);
    fur2.SetActive(true);
    fur3.SetActive(false);
    }
    if (count % 3 == 2)
    {
    fur1.SetActive(false);
    fur2.SetActive(false);
    fur3.SetActive(true);
    }
    }
    }
     
  2. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    557
    Why would you create a poll with one option...... ??? (In fact, why do you even need one?)
    And please use code tags when you post code (Left of the floppy disk).

    From your code, I think you are trying to count touches?

    Consider storing (count % 3) and then using a switch statement. You might find it easier to just add to count when a touch occurs.

    You also need to handle the touch. The documentation describes this process in detail.
     
    Last edited: Oct 4, 2015