80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
|
using DG.Tweening;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class snailRider : MonoBehaviour
|
|||
|
{
|
|||
|
public Image palye;
|
|||
|
public GameObject obj;
|
|||
|
public List<Sprite> LightSprite;
|
|||
|
public GameObject startingPoint;
|
|||
|
public GameObject end;
|
|||
|
public bool is_victory = false;//<2F><>ֻ<EFBFBD><D6BB>ţ<EFBFBD>Ƿ<EFBFBD><C7B7>ڱ<EFBFBD><DAB1>غϱ<D8BA><CFB1><EFBFBD>ʤ<EFBFBD><CAA4>
|
|||
|
public bool is_die = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD>û
|
|||
|
float offset = 0;
|
|||
|
// Start is called before the first frame update
|
|||
|
async void Start()
|
|||
|
{
|
|||
|
startMove();
|
|||
|
|
|||
|
while (true)
|
|||
|
{
|
|||
|
if (LightSprite == null) return;
|
|||
|
foreach (Sprite sprite in LightSprite)
|
|||
|
{
|
|||
|
if (palye != null)
|
|||
|
{
|
|||
|
palye.sprite = sprite;
|
|||
|
await Task.Delay(50);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
LightSprite = null;
|
|||
|
}
|
|||
|
void startMove()
|
|||
|
{
|
|||
|
palye.enabled = !is_die;
|
|||
|
if (!is_die)
|
|||
|
{
|
|||
|
float suiji = 0;
|
|||
|
if (is_victory)
|
|||
|
{
|
|||
|
suiji = UnityEngine.Random.Range(-1f,0f);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
suiji = UnityEngine.Random.Range(1f, 5f);
|
|||
|
}
|
|||
|
Sequence mySequence = DOTween.Sequence();
|
|||
|
mySequence.Append(transform.DOMove(startingPoint.transform.position, 0.01f))
|
|||
|
.Append(transform.DOMove(end.transform.position, 5f + suiji))
|
|||
|
;
|
|||
|
}
|
|||
|
|
|||
|
//+UnityEngine.Random.Range(-2f, 5.0f)
|
|||
|
}
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
offset = Mathf.Lerp(offset, 0, 1f * Time.deltaTime);
|
|||
|
obj.transform.localPosition = Vector3.Lerp(obj.transform.localPosition, new Vector3(offset, 0, 0), 1f * Time.deltaTime);
|
|||
|
}
|
|||
|
async void OnTriggerEnter2D(Collider2D other)
|
|||
|
{
|
|||
|
Destroy(other.gameObject);
|
|||
|
if (other.gameObject.GetComponent< snailRiderItem >().mode == snailRiderItem.Mode.accelerate)
|
|||
|
{
|
|||
|
offset = 500;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
offset = -500;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|