Showing posts with label control. Show all posts
Showing posts with label control. Show all posts

Friday, 23 February 2018

Unity Move Game Object With Finger swipe

Watch Video Tutorial On Youtube

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

public class Ball : MonoBehaviour
{
 private Rigidbody2D ball;
    public float BallSpeed;
    public float turnSpeen = 1;
 public float smoothTime;

    public GameObject Lose;
 Vector3 vel;
 // Use this for initialization
 void Start () {
        Lose.SetActive(false);

        ball = GetComponent<Rigidbody2D> ();
 }
 
 
 void FixedUpdate()
    {// 
        ball.velocity = new Vector2 (0, 1*BallSpeed);

  Vector3 pos =  Camera.main.ScreenToWorldPoint(Input.mousePosition);

        transform.position = Vector3.SmoothDamp (
                transform.position,
                new Vector3(pos.x, transform.position.y, transform.position.z),
                ref vel, 
                smoothTime
                );

  
 }

    void OnCollisionEnter2D(Collision2D col)
    {
        Lose.SetActive(true);
        print(col.gameObject.name);
    }
}