Need this Object to move faster and faster after time!
hi i got this script and i need the object to move faster and faster every 20 seconds! Here is the script:
public static int movespeed = 1;
public Vector3 userDirection = Vector3.up;
public void Update()
{
transform.Translate(userDirection * movespeed * Time.deltaTime);
}
void OnCollisionEnter2D(Collision2D coll)
{
Destroy(gameObject);
}
}
my object moves up perfectly but it dosent move up faster and faster please help me!
$$anonymous$$aybe you can increase the movespeed in each Upate loop using the deltaTime
Answer by xferrer · Jan 11, 2016 at 04:27 PM
Edit: I didn't see that you need only every 20 secons, sorry. I fixed it.
You can try this:
public float acceleration = 1 //used for increase the speed
public static float movespeed = 1;
public Vector3 userDirection = Vector3.up;
public void Start(){
//This will wait 20 seconds to execute for the first time and later will be executed every 20 seconds
InvokeRepeating("IncreaseSpeed", 20f, 20f);
}
public void Update()
{
transform.Translate(userDirection * movespeed * Time.deltaTime);
}
public void IncreaseSpeed(){
movespeed += acceleration;
}
void OnCollisionEnter2D(Collision2D coll)
{
Destroy(gameObject);
}
yes sure this works but i get an error:
Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
on the second script!
Answer by AlvinFassari · Jan 11, 2016 at 04:18 PM
yea i did actually try that but it didnt work that well could you maybe send me an exemple how you mean?
Your answer
Follow this Question
Related Questions
How to move object a from in front of object b to in front of object c and transfer orientation? 0 Answers
How to move object a from in front of object b to in front of object c and transfer orientation? 1 Answer
matrix4x4 apply to game object 0 Answers
Move to object if collision is triggered 0 Answers
What is the best way to script a trigger that moves a object from point a to point b in C# (unity 5) 0 Answers