arkanoid/Assets/Scripts/BallMovement.cs
2021-03-18 13:57:21 +01:00

29 lines
715 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BallMovement : MonoBehaviour
{
[Range(0,1)]
public float movementSpeed = 1f;
public Vector2 currentMotion = new Vector2(0,-1);
void FixedUpdate()
{
var x = this.transform.position.x;
var y = this.transform.position.y;
var z = this.transform.position.z;
this.transform.position = new Vector3(
x + (this.currentMotion.x * this.movementSpeed),
y,
z + (this.currentMotion.y * this.movementSpeed)
);
}
public void BounceTo(Vector2 dir)
{
this.currentMotion = Vector2.Reflect(this.currentMotion,dir);
}
}