Bär wartet nach aufwachen etc
This commit is contained in:
+78
@@ -0,0 +1,78 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
namespace WaterStylizedShader
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class FloatingObject : MonoBehaviour
|
||||
{
|
||||
public Transform[] floaters;
|
||||
public float underWaterDrag = 3f;
|
||||
public float underWaterAngularDrag = 1f;
|
||||
public float airWaterDrag = 0f;
|
||||
public float airWaterAngularDrag = 0.05f;
|
||||
|
||||
public float floatingPower = 15f;
|
||||
|
||||
public float baseWaterHeight = 0f;
|
||||
public float waterHeightVariation = 2f;
|
||||
public float waveSpeed = 1.0f;
|
||||
public float waterHeight;
|
||||
|
||||
Rigidbody rb;
|
||||
int floatersUnderwater;
|
||||
bool underwater;
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
waterHeight = baseWaterHeight + Mathf.Sin(Time.time * waveSpeed) * (waterHeightVariation / 2f);
|
||||
|
||||
floatersUnderwater = 0;
|
||||
for (int i = 0; i < floaters.Length; i++)
|
||||
{
|
||||
float diff = floaters[i].position.y - waterHeight;
|
||||
|
||||
if (diff < 0)
|
||||
{
|
||||
rb.AddForceAtPosition(Vector3.up * floatingPower * Mathf.Abs(diff), floaters[i].position, ForceMode.Force);
|
||||
floatersUnderwater++;
|
||||
if (!underwater)
|
||||
{
|
||||
underwater = true;
|
||||
SwitchState(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (underwater && floatersUnderwater == 0)
|
||||
{
|
||||
underwater = false;
|
||||
SwitchState(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SwitchState(bool isUnderwater)
|
||||
{
|
||||
if (isUnderwater)
|
||||
{
|
||||
rb.linearDamping = underWaterDrag;
|
||||
rb.angularDamping = underWaterAngularDrag;
|
||||
}
|
||||
else
|
||||
{
|
||||
rb.linearDamping = airWaterDrag;
|
||||
rb.angularDamping = airWaterAngularDrag;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f00757bc3dce824fa26206670cde47c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 297566
|
||||
packageName: Water Stylized Shader Orto & Perspective Camera
|
||||
packageVersion: 1.0
|
||||
assetPath: Assets/AureDevGames/Water Stylized Shader Orto & Perspective Camera/Scripts/FloatingObject.cs
|
||||
uploadId: 700359
|
||||
Reference in New Issue
Block a user