Question by
talehhesenov19444 · Jan 31, 2019 at 08:48 AM ·
unity 2dunity5programmingprojectproblem during runtime
2 touch Destroy(gameObject);
hi friends how can I make the object disappear when I touch 2 or more? thank you now
void OnMouseUp() {
Destroy(gameObject);
}
Comment
Answer by xxmariofer · Jan 31, 2019 at 09:03 AM
just take track of number of clicks with a int and compare the numberOfClicks value.
can you tell with code?I'm sorry I can't fully understand
int counter = 0;
void On$$anonymous$$ouseUp()
{
if(counter == 0) { counter++; }
else { counter = 0; Destroy(gameObject); }
}
{ [SerializeField]
private float fallSpeed = 3f;
public int counter = 5;
bool isOver()
{
if (EventSystem.current.currentSelectedGameObject != null) { return true; }
if (EventSystem.current.IsPointerOverGameObject()) { return true; }
if (Input.touchCount > 0 && EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) { return true; }
return false;
}
void On$$anonymous$$ouseUp()
{
if (isOver()) return;
AudioSource audio = GetComponent<AudioSource>();
audio.Play();
if (counter == 0)
{
counter++;
}
else
{
counter = 0;
Destroy(gameObject);
xal.skor++;
}
}
void Update()
{
if (transform.position.y < -6.31f)
{
Destroy(gameObject);
}
transform.position -= new Vector3(0, fallSpeed * Time.deltaTime, 0);
}
}
Your answer
Follow this Question
Related Questions
How to instantiate object dependent on position 1 Answer
2D Android Game Rapid Jumping Problem,Unity 2018.2.9f1 Android 2d Speed Jumping 0 Answers
Unity will not open project properly 0 Answers
Destroying an object with a specific name 0 Answers
Is it possible to add an Input Counter during Splash Screens? 0 Answers