using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class daoju : MonoBehaviour
{
    public Image _moveObj;
    public Image _energyPoint;
    private Vector3 _movePos = new Vector3(-189.18f, 0, 0);
    private float _energyPointMax_x = 84f;
    private float _energyPointMin_x = -100f;
    private float _targetX;
    Coroutine _onPlayCoroutine;
    void Update()
    {
        if (Input.GetKey(KeyCode.W))
        {
            _targetX = Random.Range(_energyPointMax_x, _energyPointMin_x);
            _energyPoint.rectTransform.localPosition = new Vector3(_targetX, _energyPoint.rectTransform.localPosition.y, _energyPoint.rectTransform.localPosition.z);
            if (_onPlayCoroutine != null)
                StopCoroutine(_onPlayCoroutine);
            _onPlayCoroutine = StartCoroutine(Sort());
        }
        if (Input.GetMouseButtonDown(0))
        {
            if (_onPlayCoroutine != null)
                StopCoroutine(_onPlayCoroutine);
            float Difference = (0 – _moveObj.rectTransform.localPosition.x) – (0 – _targetX);
            if (Difference > 0)
                RecordScore(Difference);
            else
                RecordScore(0-Difference);
            Debug.Log(“Move_x “ +(0- _moveObj.rectTransform.localPosition.x) + “EnergyPoint_x “ + (0 – _targetX));
        }
    }
    IEnumerator Sort()
    {
        while (true)
        {
            if (_moveObj.rectTransform.localPosition.x >= 214f)
            {
                RecordScore(0);
                if (_onPlayCoroutine != null)
                    StopCoroutine(_onPlayCoroutine);
            }
            _moveObj.rectTransform.localPosition = Vector3.MoveTowards(_moveObj.rectTransform.localPosition, new Vector3(214f, 0,0), 5);
            yield return 0;
        }
    }
    void RecordScore(float Score)
    {
        Debug.Log(Score);
    }
}