Hello, I'm new on Unity and I'm making a pong-style game. I want to make the ball accelerate every 20 secs but I dont know how to do it. Here's my code, any help will be welcome
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class bola : MonoBehaviour {
public float speedx;
public float speedy;
public float speed;
public float timeleft=20;
// Use this for initialization
void Start () {
Invoke("DireccionYvelocidadBola", 2);
}
void DireccionYvelocidadBola()
{
speedx = Random.Range(0, 4);
speedy = Random.Range(0, 4);
speed = 7f;
if (speedx==0)
{
speedx = -1;
}
if (speedy==0)
{
speedy = -1;
}
GetComponent<Rigidbody>().velocity = new Vector3(speedx * speed, speedy * speed, 0);
}
// Update is called once per frame
void Update ()
{
timeleft -= Time.deltaTime;
if (timeleft<0.01f)
{
timeleft = 20f;
speed += 2;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Problem with Pong Physics 1 Answer
Bouncy Ball stops without enough force 0 Answers
Determining if my target is standing upright 4 Answers
RayCasting 0 Answers
Rigidbody projectile misses collider 1 Answer