Hey everyone, its been a while since I’ve posted here.
I have a 2d top down shooter and i want the weapon and pickup sprites to repeatedly bob up and down in place where they spawn to highlight them as collectable objects. Must they have a rigidbody to move like that or can you just Translate the objects in game space? Perhaps Lerp? i don’t really know how to use Lerp yet.
You should be able to manipulate the translate component. An animation is propably what you are searching for, but you could apply this code to your weapon to make it scale up and down if that is what you are looking for
using UnityEngine;
public class EffectScript : MonoBehaviour {
float scaleSpeed = 3f;
float maxScale = 2f;
float minScale = 1f;
float currentScale = 1f;
float scaleDirection = 1f;
void Update () {
//Check if the scale limits are reached, if so change direction
if (currentScale <= minScale) {
scaleDirection = 1;
}
else if (currentScale >= maxScale) {
scaleDirection = -1;
}
//Calculate the new scale
currentScale += scaleSpeed * scaleDirection * Time.deltaTime;
//Apply scale to X and Y
this.transform.localScale = new Vector3(currentScale,currentScale, 0);
}
}