Please help…
whenever I’m clicking mouse button ball bounce… please help me what to do
here is my ball code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour {
private Paddle paddle;
private bool hasStarted = false;
private Vector3 paddleToBallVector;
// Use this for initialization
void Start () {
paddle = GameObject.FindObjectOfType<Paddle>();
paddleToBallVector = this.transform.position - paddle.transform.position;
}
// Update is called once per frame
void Update ()
{
{
if (!hasStarted)
//Lock the ball relative to the paddle.
this.transform.position = paddle.transform.position + paddleToBallVector;
//Wait for a mouse press to launch.
if (Input.GetMouseButtonDown (1)) {
print ("Mouse Clicked, launch ball");
hasStarted = true;
GetComponent<Rigidbody2D>().velocity = transform.up *10.5f ;
}
}
}
void OnCollissionEnter2D (Collision2D collision)
{
Vector3 tweak = new Vector3 (Random.Range (0f, 0.2f), Random.Range (0f, 0.2f), 0f);
print (tweak);
if (hasStarted) {
}
}
}
``