Beispiel #1
0
    private void FixedUpdate()
    {
        updateDistanceMatrix();
        link = new List <int>();
        if (distanceMatrix[0][1] <= maxDistance)
        {
            link.Add(0); link.Add(1);
        }
        else
        {
            minLength = float.MaxValue;
            List <int> temp = new List <int>();
            minDistance(temp, 0, 1, 0f);
        }

        if (link.Count == 0)
        {
            LifeTime -= Time.fixedDeltaTime;
            // 断开连接
            chainLightning.StartPosition = null;
            chainLightning.EndPostion    = null;
            lineRenderer.enabled         = false;
        }
        else
        {
            LifeTime = maxLifeTime;
            // 连接电流
            lineRenderer.enabled         = true;
            chainLightning.StartPosition = transforms[link[0]];
            chainLightning.EndPostion    = new List <Transform>();
            for (int i = 1; i < link.Count; i++)
            {
                chainLightning.EndPostion.Add(transforms[link[i]]);
            }
        }
        if (LifeTime <= 0f)
        {
            if (instance != null)
            {
                instance.Die();
            }
            else if (game1Instance != null)
            {
                game1Instance.Die();
            }
            else
            {
                Debug.LogError("No game manager instance.");
            }
            //LifeTime = maxLifeTime;
        }
    }
Beispiel #2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject item  = collision.gameObject;
        int        layer = 1 << item.layer;

        if (layer == player.value)
        {
            gameObject.GetComponent <Collider2D>().enabled = false;
            if (instance != null)
            {
                instance.Die();
            }
            else
            {
                game1Instance.Die();
            }
        }
    }