Compare commits
2 Commits
13d5237c6b
...
43a50d5374
Author | SHA1 | Date |
---|---|---|
|
43a50d5374 | 2 years ago |
|
8e8f1345ed | 2 years ago |
7 changed files with 122 additions and 6 deletions
@ -0,0 +1,19 @@ |
|||||||
|
%YAML 1.1 |
||||||
|
%TAG !u! tag:unity3d.com,2011: |
||||||
|
--- !u!114 &11400000 |
||||||
|
MonoBehaviour: |
||||||
|
m_ObjectHideFlags: 0 |
||||||
|
m_CorrespondingSourceObject: {fileID: 0} |
||||||
|
m_PrefabInstance: {fileID: 0} |
||||||
|
m_PrefabAsset: {fileID: 0} |
||||||
|
m_GameObject: {fileID: 0} |
||||||
|
m_Enabled: 1 |
||||||
|
m_EditorHideFlags: 0 |
||||||
|
m_Script: {fileID: 11500000, guid: 4453d1448ec14f5fa81aae3c54f78010, type: 3} |
||||||
|
m_Name: WidthBuff |
||||||
|
m_EditorClassIdentifier: |
||||||
|
type: 1 |
||||||
|
effect: 2 |
||||||
|
pickupDuration: 10 |
||||||
|
activeDuration: 10 |
||||||
|
image: {fileID: 21300000, guid: f09eae8c0ea04254b90c5386a034a225, type: 3} |
@ -0,0 +1,8 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: 3237b9257f669690ea1a6f828451509e |
||||||
|
NativeFormatImporter: |
||||||
|
externalObjects: {} |
||||||
|
mainObjectFileID: 11400000 |
||||||
|
userData: |
||||||
|
assetBundleName: |
||||||
|
assetBundleVariant: |
@ -0,0 +1,19 @@ |
|||||||
|
%YAML 1.1 |
||||||
|
%TAG !u! tag:unity3d.com,2011: |
||||||
|
--- !u!114 &11400000 |
||||||
|
MonoBehaviour: |
||||||
|
m_ObjectHideFlags: 0 |
||||||
|
m_CorrespondingSourceObject: {fileID: 0} |
||||||
|
m_PrefabInstance: {fileID: 0} |
||||||
|
m_PrefabAsset: {fileID: 0} |
||||||
|
m_GameObject: {fileID: 0} |
||||||
|
m_Enabled: 1 |
||||||
|
m_EditorHideFlags: 0 |
||||||
|
m_Script: {fileID: 11500000, guid: 4453d1448ec14f5fa81aae3c54f78010, type: 3} |
||||||
|
m_Name: WidthNerf |
||||||
|
m_EditorClassIdentifier: |
||||||
|
type: 0 |
||||||
|
effect: 2 |
||||||
|
pickupDuration: 10 |
||||||
|
activeDuration: 10 |
||||||
|
image: {fileID: 21300000, guid: f9161c6c9e06dc445ada3ee16d991f90, type: 3} |
@ -0,0 +1,8 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: c6de04aab82eeff81894387c19ac1310 |
||||||
|
NativeFormatImporter: |
||||||
|
externalObjects: {} |
||||||
|
mainObjectFileID: 11400000 |
||||||
|
userData: |
||||||
|
assetBundleName: |
||||||
|
assetBundleVariant: |
@ -1,17 +1,72 @@ |
|||||||
|
using System.Collections; |
||||||
|
using System.Linq; |
||||||
using Unity.Netcode; |
using Unity.Netcode; |
||||||
using UnityEngine; |
using UnityEngine; |
||||||
|
|
||||||
namespace Game { |
namespace Game { |
||||||
public class Wormhole : NetworkBehaviour { |
public class Wormhole : NetworkBehaviour { |
||||||
|
|
||||||
public float Size { get; set; } |
public float duration = 10; |
||||||
|
|
||||||
private void Start() { |
private const float MaxSize = 10; |
||||||
transform.localScale = new Vector3(Size, Size, Size); |
|
||||||
|
private float size; |
||||||
|
public float Size { |
||||||
|
get => size; |
||||||
|
set { |
||||||
|
size = value; |
||||||
|
transform.localScale = new Vector3(size, size, 1); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private float Radius => Size / 2; |
||||||
|
|
||||||
|
private static float CubicEaseInOut(float t, float b, float c, float d) { |
||||||
|
if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; |
||||||
|
return c / 2 * ((t -= 2) * t * t + 2) + b; |
||||||
|
} |
||||||
|
|
||||||
|
private static float CircleEaseInOut(float t, float b, float c, float d) { |
||||||
|
if ((t /= d / 2) < 1) return -c / 2 * (Mathf.Sqrt(1 - t * t) - 1) + b; |
||||||
|
return c / 2 * (Mathf.Sqrt(1 - (t -= 2) * t) + 1) + b; |
||||||
|
} |
||||||
|
|
||||||
|
private IEnumerator Grow(float growTime) { |
||||||
|
float currentTime = 0; |
||||||
|
while (currentTime <= growTime) { |
||||||
|
Size = CircleEaseInOut(currentTime, 0, MaxSize, growTime); |
||||||
|
yield return new WaitForFixedUpdate(); |
||||||
|
currentTime += Time.fixedDeltaTime; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private IEnumerator Shrink(float shrinkTime) { |
||||||
|
float currentTime = 0; |
||||||
|
while (currentTime <= shrinkTime) { |
||||||
|
Size = CubicEaseInOut(currentTime, MaxSize, -MaxSize, shrinkTime); |
||||||
|
yield return new WaitForFixedUpdate(); |
||||||
|
currentTime += Time.fixedDeltaTime; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private IEnumerator Start() { |
||||||
|
Size = 0; |
||||||
|
yield return Grow(duration * 0.2f); |
||||||
|
yield return new WaitForSeconds(duration * 0.7f); |
||||||
|
yield return Shrink(duration * 0.1f); |
||||||
} |
} |
||||||
|
|
||||||
private void FixedUpdate() { |
private void FixedUpdate() { |
||||||
foreach (var ball in GameManager.Singleton.Balls) { } |
Vector2 thisPos = new Vector2(transform.position.x, transform.position.y); |
||||||
|
foreach (var ball in GameManager.Singleton.Balls) { |
||||||
|
Vector2 diff = thisPos - ball.Rb.position; |
||||||
|
if (diff.sqrMagnitude > Radius * Radius) |
||||||
|
continue; |
||||||
|
float dist = diff.magnitude; |
||||||
|
Vector2 force = diff.normalized / dist * (Size * 5); |
||||||
|
force = Vector2.ClampMagnitude(force, 15); |
||||||
|
ball.Rb.AddForce(force); |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue