- Home /
Question by
qaziJunaid · Sep 25, 2017 at 02:51 AM ·
rigidbody2ddestroy objectflying
Array of different rigidbody
Hy,I am new to unity and i making a simple game in which i want different balloons will fly from random position and user will destroy them when touched. One object is flying and doing as i want but i don't know how to take random objects and then make them fly...`using System.Collections; using System.Collections.Generic; using UnityEngine;
public class BallonSpawn : MonoBehaviour {
public GameObject Ballon;
public Rigidbody2D rb;
public float maxpos = 4.0f;
public float delaytimer = 1f;
public float timer;
public float speed = 3f;
public int score = 0;
// Use this for initialization
void Start ()
{
timer = delaytimer;
}
// Update is called once per frame
void Update ()
{
Vector3 movement = transform.up;
Vector3 direction = movement.normalized;
Vector3 velocity = direction * speed;
rb.position = velocity * Time.deltaTime;
timer -= Time.deltaTime;
if (timer <= 0)
{
Vector3 Ballonpos = new Vector3 (Random.Range(-4.0f,4.0f) , transform.position.y , transform.position.z);
Instantiate (Ballon, Ballonpos, transform.rotation);
timer = delaytimer;
}
if (Input.touchCount > 0)
{
print ("ther is a touch");
}
}
/*void (Collision col)
{
//if(other.gameObject.CompareTag("Coin"))
if(Input.touchCount > 0)
{
col.gameObject.SetActive(false);
score = score + 1;
}
}*/
}`
Comment