Ejemplo n.º 1
0
 private void Start()
 {
     Knight.Log("Created a firepillar with lifespan " + _lifespan + " and strength " + _strength);
     Knight.Log("Current location is " + gameObject.transform.GetPositionX() + ", " + gameObject.transform.GetPositionY());
     StartCoroutine(Animate());
     _selfTexture = gameObject.GetComponent <Texture2D>();
 }
Ejemplo n.º 2
0
        public void DrawRay()
        {
            lr.startWidth = 0.3f;
            lr.endWidth   = 0.3f;
            // Bit shift the index of the layer (8) to get a bit mask
            int          layerMask = 1 << 8;
            var          position  = transform.position;
            RaycastHit2D hit       = Physics2D.Raycast(new Vector2(position.x, position.y), Vector2.down, Mathf.Infinity, layerMask);

            if (hit)
            {
                var       position1 = transform.position;
                Vector3[] positions = new[] { position1, position1 + hit.distance * Vector3.down };
                lr.SetPositions(positions);
                //Knight.Log("Did Hit " + hit.distance + " normal is " + hit.normal);
            }
            else
            {
                var       position1 = transform.position;
                Vector3[] positions = new[] { position1, position1 + 100f * Vector3.down };
                lr.SetPositions(positions);
                lr.colorGradient = new Gradient();
                Knight.Log("Did not Hit");
            }
        }
Ejemplo n.º 3
0
        public static void SpawnFirePillar(float strength)
        {
            GameObject firePillar = new GameObject("redwingFlamePillar", typeof(firepillar),
                                                   typeof(SpriteRenderer), typeof(Rigidbody2D), typeof(BoxCollider2D));

            firePillar.transform.localScale = new Vector3(strength, strength, 1f);
            GameObject fireAtJerk = null;

            if (Knight.PillarDetection.isEnemyInRange())
            {
                try
                {
                    fireAtJerk = Knight.PillarDetection.firePillarTarget();
                }
                catch (Exception e)
                {
                    Knight.Log("Spawn fire pillar failed with error " + e);
                }
            }

            if (fireAtJerk != null)
            {
                firePillar.transform.parent        = null;
                firePillar.transform.localPosition = Vector3.zero;
                Vector3 position = fireAtJerk.gameObject.transform.position;
                Vector3 pillarRelativePosition = new Vector3(
                    position.x,
                    Knight.KnightGameObject.transform.position.y,
                    position.z - 0.003f);
                firePillar.transform.position = pillarRelativePosition;
            }
            else
            {
                firePillar.transform.parent        = Knight.KnightGameObject.transform;
                firePillar.transform.localPosition = Vector3.zero;
            }
            SpriteRenderer img = firePillar.GetComponent <SpriteRenderer>();
            Rect           pillarSpriteRect = new Rect(0, 0,
                                                       PillarWidth, PillarHeight);

            img.sprite = Sprite.Create(textures.FocusBeam[0], pillarSpriteRect,
                                       new Vector2(0.5f, 0.5f), 30f);
            img.color = new Color(1f, 1f, 1f, 0.5f + strength * 0.5f);
            //img.enabled = true;

            Rigidbody2D fakePhysics = firePillar.GetComponent <Rigidbody2D>();

            fakePhysics.isKinematic = true;
            BoxCollider2D hitEnemies = firePillar.GetComponent <BoxCollider2D>();

            hitEnemies.isTrigger = true;
            hitEnemies.size      = img.size;
            hitEnemies.offset    = new Vector2(0, 0);

            firepillar f = firePillar.GetComponent <firepillar>();

            f._lifespan = PillarLifespan;
            f._strength = strength;
            firePillar.SetActive(true);
        }