Platform wiggelt
This commit is contained in:
39
Assets/AssetsFORELLE/Script/Wiggler.cs
Normal file
39
Assets/AssetsFORELLE/Script/Wiggler.cs
Normal 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;}
|
||||
}
|
||||
}
|
11
Assets/AssetsFORELLE/Script/Wiggler.cs.meta
generated
Normal file
11
Assets/AssetsFORELLE/Script/Wiggler.cs.meta
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36fbcd880fbe94356ae4f9ee7a037a8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user