Пример #1
0
    IEnumerator lerpMagicLine(float speed, talisman target)
    {
        float         startTime    = Time.time;
        GameObject    line         = Instantiate(magicLine, transform.position, transform.rotation, null);
        TrailRenderer trail        = line.GetComponent <TrailRenderer>();
        float         delay        = trail.time;
        bool          countingDown = false;

        while (delay > 0)
        {
            if (!countingDown)
            {
                if (Vector3.SqrMagnitude(target.transform.position - line.transform.position) < nearbyDistance)
                {
                    countingDown = true;
                    target.ReceivePing();
                }
            }
            if (countingDown)
            {
                delay     -= Time.deltaTime * 5;
                trail.time = delay;
            }
            Vector3 position = Vector3.MoveTowards(line.transform.position, target.transform.position, speed * Time.deltaTime);
            line.transform.position = position;
            yield return(null);
        }
    }
Пример #2
0
    void handleSelection()
    {
        if (raycastHitHistory.Count > holdTime)
        {
            raycastHitHistory.RemoveAt(0);
        }

        talisman raycastHitTalisman = null;

        for (int i = raycastHitHistory.Count - 1; i >= 0; i--)
        {
            if (raycastHitHistory[i] != null)
            {
                raycastHitTalisman = raycastHitHistory[i];
                break;
            }
        }

        switch (state)
        {
        case selectionState.none:
            firstSelection = raycastHitTalisman;
            break;

        case selectionState.firstSelectionMade:
            if (raycastHitTalisman != firstSelection)
            {
                secondSelection = raycastHitTalisman;
            }
            break;
        }
    }
Пример #3
0
    void checkInput()
    {
        if (Input.GetButtonDown("Fire1") && firstSelection != null)
        {
            state = selectionState.firstSelectionMade;
        }
        if (Input.GetButtonUp("Fire1"))
        {
            state = selectionState.none;
            orderPing();

            firstSelection  = null;
            secondSelection = null;
        }
    }
Пример #4
0
    void performRaycast()
    {
        talisman raycastHitTalisman = null;

        RaycastHit hitInfo = new RaycastHit();
        Ray        ray     = new Ray(transform.position, transform.localToWorldMatrix * Vector3.forward);

        Debug.DrawRay(transform.position, transform.forward);
        Physics.Raycast(new Ray(transform.position, transform.localToWorldMatrix * Vector3.forward), out hitInfo);

        if (hitInfo.collider != null)
        {
            raycastHitTalisman = hitInfo.collider.GetComponent <talisman>();
        }

        raycastHitHistory.Add(raycastHitTalisman);
    }
Пример #5
0
    public int Compare(object x, object y)
    {
        talisman talismanX = (talisman)x;
        talisman talismanY = (talisman)y;

        float distSqrX = Vector3.SqrMagnitude(talismanX.transform.position - transform.position);
        float distSqrY = Vector3.SqrMagnitude(talismanY.transform.position - transform.position);

        if (distSqrX < distSqrY)
        {
            return(-1);
        }

        if (distSqrX == distSqrY)
        {
            return(0);
        }

        return(1);
    }
Пример #6
0
    IEnumerator lerpMagicLineTimed(float time, talisman target)
    {
        float         progress     = 0;
        GameObject    line         = Instantiate(magicLine, transform.position, transform.rotation, null);
        TrailRenderer trail        = line.GetComponent <TrailRenderer>();
        float         delay        = trail.time;
        bool          countingDown = false;

        while (delay > 0)          //while the line has a reason to maintain its position
        {
            if (!countingDown)     //if the line has not yet reached the target talisman
            {
                if (progress >= 1) //if the line actually has though
                {
                    progress     = 1;
                    countingDown = true;  //start retracting the tail of the line
                    target.ReceivePing(); //tell the target that we made it
                }
                else //otherwise keep increasing progress until it > 1
                {
                    progress += Time.deltaTime / time;
                }
            }

            if (countingDown) //if we are retracting the tail of the line
            {
                delay     -= Time.deltaTime * 5;
                trail.time = delay;
                if (trail.time <= 0)
                {
                    Destroy(trail.gameObject);
                }
            }

            Vector3 position = Vector3.Lerp(transform.position, target.transform.position, progress);
            line.transform.position = position;
            yield return(null);
        }
    }
Пример #7
0
 public void Ping(talisman target)
 {
     Flash();
     StartCoroutine(lerpMagicLineTimed(1.5f, target));
 }
Пример #8
0
 void TimedPing(talisman target)
 {
 }
Пример #9
0
 // Use this for initialization
 void Start()
 {
     firstSelection  = null;
     secondSelection = null;
 }