42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class Chip : MonoBehaviour
|
|
{
|
|
public CellState Team;
|
|
[SerializeField] float linearSpeed = 50f;
|
|
[SerializeField] float acceleration = 200f;
|
|
[SerializeField] float maxFallingRotationSpeed = 500;
|
|
|
|
private float chipVelocity = 0;
|
|
private float rotationSpeed = 0;
|
|
|
|
public virtual void RemoveFromField()
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public bool MoveToLinear(Vector2 target)
|
|
{
|
|
transform.position = Vector2.MoveTowards(transform.position, target, linearSpeed * Time.deltaTime);
|
|
if((Vector2)transform.position == target)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public bool MoveToAccelerated(Vector2 target)
|
|
{
|
|
transform.position = Vector2.MoveTowards(transform.position, target, chipVelocity * Time.deltaTime);
|
|
chipVelocity += acceleration * Time.deltaTime;
|
|
|
|
if ((Vector2)transform.position == target)
|
|
{
|
|
acceleration = 0;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
public void SetRandomRotationSpeed() => rotationSpeed = Random.Range(-maxFallingRotationSpeed, maxFallingRotationSpeed);
|
|
public void Rotate() => transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
|
|
} |