private void FixedUpdate()
    {
        if (yesBe)
        {
            uv += speed / motionPath.length * Time.fixedDeltaTime;
            //uv += ((speed) * Time.fixedDeltaTime);			// This gets you uv amount per second so speed is in realworld units
            if (loop)
            {
                uv = (uv < 0 ? 1 + uv : uv) % 1;
            }
            else if (uv > 1)
            {
                enabled = false;
            }
            var pos  = motionPath.PointOnNormalizedPath(uv);
            var norm = motionPath.NormalOnNormalizedPath(uv);

            transform.position = pos;
            transform.forward  = speed > 0 ? norm : -norm;
            if (is2d)
            {
                transform.eulerAngles = new Vector3(0, 0, 0);
            }
            else
            {
                transform.LookAt(lookAt);
            }
        }
    }
    /// <summary>
    /// Spawns the button using a prefab and initiates it with the variables you give it. Also returns the button as a gameObject
    /// </summary>
    /// <param name="uv">Percentage of the BeatPath</param>
    /// <param name="type">Type of button</param>
    /// <param name="beat">Beat of button</param>
    /// <param name="indexin">Index of the button</param>
    /// <param name="track">The Track to spawn on (0-1)</param>
    /// <returns></returns>
    public GameObject Spawn(float uv, float type, bool sustain, float beat, int track)
    {
        var buttonPos = new Vector3(path.PointOnNormalizedPath(uv).x, path.PointOnNormalizedPath(uv).y,
                                    buttonPrefab.transform.position.z);
        var button = Instantiate(buttonPrefab, buttonPos, new Quaternion(0, 0, 0, 0));

        if (track != 0)
        {
            button.transform.up = path.NormalOnNormalizedPath(uv);
            var offset = transform.right * (trackOffset * -1);
            if (gameHandler.cursorFlipped)
            {
                offset = transform.right * (trackOffset * 1);
            }
            button.transform.Translate(offset, Space.Self);
            button.transform.eulerAngles = new Vector3(0, 0, 0);
        }

        // If Type given does not exist, switch to Star(0)
        if (Mathf.RoundToInt(type) >= gameHandler.NoteTypes.Length)
        {
            type = 0;
        }
        var btnClass = button.GetComponent <Button>();

        btnClass.Init(Mathf.RoundToInt(type), sustain, beat, track);
        return(button);
    }
예제 #3
0
    void FixedUpdate()
    {
        uv += ((speed / motionPath.length) * Time.fixedDeltaTime);                              // This gets you uv amount per second so speed is in realworld units
        if (loop)
        {
            uv = (uv < 0?1 + uv:uv) % 1;
        }
        else if (uv > 1)
        {
            enabled = false;
        }
        Vector3 pos  = motionPath.PointOnNormalizedPath(uv);
        Vector3 norm = motionPath.NormalOnNormalizedPath(uv);

        transform.position = pos;
        transform.forward  = speed > 0?norm:-norm;
    }