Beispiel #1
0
        private LogSpace LogSpaceTransform()
        {
            LogSpace logSpace = null;

            for (int i = 0; i < _LogSpaces.Count; i++)
            {
                if (_LogSpaces[i].CurrentState == LogSpaceState.Empty)
                {
                    return(_LogSpaces[i]);
                }
            }

            return(logSpace);
        }
Beispiel #2
0
        private void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag == "Logs" && other.gameObject.GetComponentInParent <Rigidbody>() != null)
            {
                Log log = other.GetComponentInParent <Log>();
                if (log != null && log.CurrentState == LogState.InField)
                {
                    log.CurrentState = LogState.moving;

                    LogSpace logSpace = LogSpaceTransform();
                    logSpace.CurrentState = LogSpaceState.Filling;

                    StartCoroutine(LerpTo(logSpace, log));
                }
            }
        }
Beispiel #3
0
        private IEnumerator LerpTo(LogSpace target, Log log)
        {
            float elapsedTime = 0f;

            Debug.Log("Starting Lerp");
            log.LogPlaced();

            while (elapsedTime < _duration)
            {
                float value = Curve.Evaluate((elapsedTime / _duration));

                //Position
                log.transform.position = Vector3.Lerp(log.transform.position, target.transform.position, value);

                //Rotation
                Vector3 rotation = Vector3.Lerp(log.transform.rotation.eulerAngles, target.transform.rotation.eulerAngles, value);
                rotation = new Vector3(0, rotation.y, 0);
                log.transform.eulerAngles = rotation;


                elapsedTime += Time.deltaTime;
                yield return(null);
            }

            //Locking values
            log.transform.position = target.transform.position;
            log.transform.rotation = target.transform.rotation;

            target.CurrentState = LogSpaceState.Filled;
            log.CurrentState    = LogState.Placed;

            _logsPlaced.Add(log);

            OnLogPlaced(log);
            Debug.Log("Completed Lerp");

            target.SpaceFilled();

            LogSpacesFilledCheck();

            yield return(null);
        }