Question by
mike1233 · Jan 31, 2017 at 07:47 PM ·
androidiosmobilemobile devices
is coding for mobile touch scripts same for android as for ios apple?
is coding for mobile touch scripts same for android as for ios apple?
so will this code work in ios apple iphones also or just android?
using UnityEngine;
using System.Collections;
public class Toucht : MonoBehaviour
{
public float upForce;
public float downForce;
public float forwardSpeed;
public bool isDead = false;
Animator anim;
bool flap = false;
void Start()
{
anim = GetComponent<Animator> ();
GetComponent<Rigidbody2D>().velocity = new Vector2 (forwardSpeed, 0);
}
void Update()
{
if (isDead)
return;
Touch myTouch = Input.GetTouch(0);
Touch[] myTouches = Input.touches;
for(int i = 0; i < Input.touchCount; i++)
flap = true;
}
void FixedUpdate()
{
if (flap)
{
flap = false;
anim.SetTrigger ("Flap");
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, 0);
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, upForce));
}
if (Input.GetKeyDown("t"))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 0);
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (-0, downForce));
}
}
int hit = 0;
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag == "Wall")
{
hit++;
if(hit >= 25)
Destroy(gameObject);
}
if(other.gameObject.tag == "Wall")
{
GetComponent<AudioSource>().Play();
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Move Character using Finger Gestures for Unity 0 Answers
For iOS development what image sizes do I need? 1 Answer
How to Get to another app 0 Answers
Multiple Scenes for iOS 2 Answers
Can someone help me fix this awesome ColorPicker code ? 0 Answers