Пример #1
0
    private void FireProj(float offset, float spread, float vel)
    {
        float      s         = Random.Range(-spread * Mathf.PI / 180, spread * Mathf.PI / 180);
        Vector2    ddir      = new Vector2(dir.x * Mathf.Cos(s) - dir.y * Mathf.Sin(s), dir.x * Mathf.Sin(s) + dir.y * Mathf.Cos(s));
        Vector3    launchPos = transform.position + offset * dir;
        Quaternion rot       = Quaternion.Euler(0, 0, Vector3.Angle(Vector3.right, ddir) * (Vector3.Dot(Vector3.up, ddir) / (Mathf.Abs((Vector3.Dot(Vector3.up, ddir))))));
        GameObject ob        = Instantiate(proj, launchPos, rot) as GameObject;

        if (ob != null)
        {
            Rigidbody2D rp;
            ob.tag   = "Projectile"; //tag
            ob.layer = 8;
            if (ob.GetComponent <Rigidbody2D>() != null)
            {
                rp          = ob.GetComponent <Rigidbody2D>();
                rp.velocity = vel * ddir;
            }
            if (ob.GetComponent <ProjectileTest>())
            {
                ProjectileTest p = ob.GetComponent <ProjectileTest>();
                p.SetParent(gameObject);
                if (delTime > 0)
                {
                    p.deleteTime = delTime;
                }
                //STUFF
            }
        }
    }
Пример #2
0
    private void SummonOrb()
    {
        GameObject     ob = Instantiate(prefab, pPos + Vector3.right, Quaternion.Euler(0, 0, 0)) as GameObject;
        ProjectileTest p  = ob.GetComponent <ProjectileTest>();

        p.parentObj  = gameObject;
        p.deleteTime = delTime;
        projs.Add(ob);
    }
Пример #3
0
    void FixedUpdate()
    {
        pPos = gameObject.transform.position; //FIX

        if (Time.time > ti + spawnPeriod && projs.Count <= maxCount)
        {
            SummonOrb();
            ti = Time.time;
        }

        foreach (GameObject el in projs)
        {
            if (el == null)
            {
                projs.Remove(el);
                break;
            }
            else
            {
                if (el != null && el.GetComponent <Rigidbody2D>() != null && el.GetComponent <ProjectileTest>() != null)
                {
                    ProjectileTest p  = el.GetComponent <ProjectileTest>();
                    Rigidbody2D    rb = el.GetComponent <Rigidbody2D>();
                    if (p.parentObj != null && p.parentObj == gameObject)
                    {
                        Vector3 rPos = (el.transform.position - pPos);
                        Vector2 perp = new Vector2(-rPos.y, rPos.x).normalized;
                        switch (mode)
                        {
                        case 0:
                            SwingProj(perp, rPos, rb);
                            break;

                        case 1:
                            RingV2(projs.IndexOf(el), rb);
                            break;
                        }
                    }
                }
            }
        }
    }