Platform wiggelt

This commit is contained in:
DominikB
2023-06-27 18:39:27 +02:00
parent 6d18c44ff0
commit f3951918f3
6 changed files with 95 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
using UnityEngine;
public class Wiggler : MonoBehaviour
{
public float wiggleAmount = 1f; // Amount of wiggle (distance) from left to right
public float wiggleSpeed = 1f; // Speed of the wiggle
private Vector2 startPosition;
private float time;
public GameObject _LevelManager1;
private ButtonDOne script1;
private bool einsAn = false;
void Start()
{
startPosition = transform.position;
}
void Update()
{
script1 = _LevelManager1.GetComponent<ButtonDOne>();
einsAn = script1.einsAn;
if(einsAn){
// Calculate the horizontal position using a sine wave
float xPosition = startPosition.x + Mathf.Sin(time * wiggleSpeed) * wiggleAmount;
// Set the new position of the game object
transform.position = new Vector2(xPosition, transform.position.y);
// Increment the time variable based on the elapsed time
time += Time.deltaTime;}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 36fbcd880fbe94356ae4f9ee7a037a8b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: