Akaranan Weerayanphan


Pinball
Genre : 2D , Arcade
Platform : PC (Play in Browser)
Mode : Single Player
"PinBall" เป็นเกมแรกที่ได้สร้างด้วยโปรแกรมUnityจากการเรียนในวิชา Physics for Gameในปี2 ที่มหาวิทยาลัยกรุงเทพ
public class Shoot : MonoBehaviour
{
Rigidbody rb;
[SerializeField] private Text life,Score;
int ball;
float force, acc;
[SerializeField] Transform ballUp;
[SerializeField] Rigidbody ballUpR;
private void Start()
{
rb = GetComponent<Rigidbody>();
ballUpR = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
if (life.text == "3") ball = 3;
if (life.text == "2") ball = 2;
if (life.text == "1") ball = 1;
}
public void shootSlow()
{
acc = 2000;
ShootBall();
}
public void shootFast()
{
acc = 3000;
ShootBall();
}
public void ShootBall()
{
force = rb.mass * acc;
if (ball > 0)
{
rb.AddForce(0,force, 0);
ball--;
life.text = "" + ball;
}
if (ball <= 0)
{
life.text = "Please Restart";
}
}
private void OnTriggerEnter(Collider other)
{
if(this.gameObject.name == "ballUp")
{
int.TryParse(life.text ,out int a);
a++;
ballUp.position = new Vector3(18, -12, 55);
if (life.text == "Please Restart") { life.text = "1"; }
else
life.text = ""+a;
}
}
}


