示例#1
0
    void shootRod()
    {
        float   speed   = 10.0f;
        Vector2 gravity = new Vector2(0.0f, -2.0f);

        Debug.LogWarning("the f***s");

        GameObject proj = Instantiate(projectile, gameObject.transform.position, gameObject.transform.rotation);
        Particle2D temp = proj.GetComponent <Particle2D>();

        temp.Velocity     = transform.right * speed;
        temp.Acceleration = gravity;
        temp.Mass         = 1.0f;
        GameManager.Instance.mObjects.Add(temp);

        GameObject proj1 = Instantiate(projectile, (gameObject.transform.position + new Vector3(2.5f, 2.5f)), gameObject.transform.rotation);

        Debug.LogError(proj1.transform.position);
        Debug.LogError(proj.transform.position);
        temp              = proj1.GetComponent <Particle2D>();
        temp.Velocity     = transform.right * (speed + 2.0f);
        temp.Acceleration = gravity;
        temp.Mass         = 1.0f;
        GameManager.Instance.mObjects.Add(temp);

        Particle2DLink link = new Particle2DLink(proj, proj1, 1.0f);

        mLinks.Add(link);
    }
示例#2
0
    public static void MakeProjectile(Transform trans, GameObject type)
    {
        GameObject projectile = Instantiate(type, trans.position, trans.rotation);
        Vector3    direction  = Vector3.right;
        float      angle      = trans.eulerAngles.z * Mathf.Deg2Rad;
        float      sin        = Mathf.Sin(angle);
        float      cos        = Mathf.Cos(angle);

        Vector3 forward = new Vector3(
            direction.x * cos - direction.y * sin,
            direction.x * sin + direction.y * cos,
            0f);



        projectile.GetComponent <Particle2D>().Create(1, forward, new Vector2(0, -.01f), 0.999f, 10, unitID);
        particleList.Add(projectile);
        unitID += 1;
        if (type.name.Contains("Spring"))
        {
            GameObject projectile2 = Instantiate(type, trans.position, trans.rotation);
            projectile2.GetComponent <Particle2D>().Create(1, forward, new Vector2(0, -.01f), 0.999f, 1, unitID);
            particleList.Add(projectile2);
            unitID += 1;
            SpringGenerator newGenerator = new SpringGenerator();
            newGenerator.SetShouldEffectAll(false);
            ForceManager.AddGenerator(newGenerator);
            newGenerator.SetID(projectile.GetComponent <Particle2D>().GetID(), projectile2.GetComponent <Particle2D>().GetID());
        }
        else if (type.name.Contains("Rod"))
        {
            GameObject projectile2 = Instantiate(type, trans.position, trans.rotation);
            projectile2.GetComponent <Particle2D>().Create(1, forward, new Vector2(0, -.01f), 0.999f, 2, unitID);
            particleList.Add(projectile2);
            unitID += 1;
            Particle2DLink newLink = new Particle2DLink();
            newLink.id1 = projectile.GetComponent <Particle2D>().GetID();
            newLink.id2 = projectile2.GetComponent <Particle2D>().GetID();

            linkList.Add(newLink);
        }
    }
示例#3
0
    // Start is called before the first frame update
    void Start()
    {
        //Set Boundries
        topBoundry    = GameObject.Find("TopBoundry");
        bottomBoundry = GameObject.Find("BottomBoundry");
        leftBoundry   = GameObject.Find("LeftBoundry");
        rightBoundry  = GameObject.Find("RightBoundry");

        //Set Game Manager
        gameManager = GameObject.Find("Player");

        //Get Components
        if (forceGen)
        {
            forceGen = gameObject.GetComponent <ForceGenerator2D>();
        }

        if (particleLink)
        {
            particleLink = gameObject.GetComponent <Particle2DLink>();
        }
    }
示例#4
0
 public void DeleteParticleLink(Particle2DLink link)
 {
     mParticleLinks.Remove(link);
 }
示例#5
0
 public void AddParticleLink(Particle2DLink link)
 {
     mParticleLinks.Add(link);
 }
    //Shooting Bullets Controls
    void ShootingControls()
    {
        //W - Change Bullet
        if (Input.GetKeyDown(KeyCode.W) == true)
        {
            if (bulletNum >= 3) //Reset back to one if reaches 3
            {
                bulletNum = 1;
            }
            else
            {
                bulletNum += 1;
            }
            Debug.Log("Bullet: " + bulletNum);
        }

        //Creat Bullet
        if (Input.GetKeyDown(KeyCode.Return) == true)
        {
            switch (bulletNum)
            {
            case 1:     //Bullet
                Debug.Log("Bullet");

                //Create Bullet
                GameObject bulletOne = Instantiate(bullet);
                //bulletOne.transform.position = gunEnd.transform.position;

                //Set Variables
                //particleManager.AddParticle(bullet);
                bulletOne.GetComponent <Bullets>().SetBulletVariables(bulletOne, gunEnd);

                //Transform Position
                bulletOne.transform.position = gunEnd.transform.position;
                bulletOne.transform.rotation = gunEnd.transform.rotation;

                //Force Generator
                bulletOne.GetComponent <Bullets>().isForceGen = true;
                ForceGenerator2D BouyancyGen2 = forceManager.CreateBouyancyForceGenerator(bulletOne, (waterSprite.transform.localScale.y) / 2.0f, 75.0f, 5.0f, -(waterSprite.transform.localScale.y) / 2.0f);
                forceManager.AddForceGenerator(BouyancyGen2);
                bulletOne.GetComponent <Bullets>().forceGen = BouyancyGen2;

                break;

            case 2:     //Spring
                Debug.Log("Spring");

                //Set Value
                int numSprings = 1;

                //Create Bullets
                GameObject springOne = Instantiate(springBullet);
                springOne.name = "Spring" + numSprings;
                numSprings++;
                GameObject springTwo = Instantiate(springBullet);
                springTwo.name = "Spring" + numSprings;
                numSprings++;

                //Set Variables
                springOne.GetComponent <Bullets>().SetBulletVariables(springOne, gunEnd);
                springTwo.GetComponent <Bullets>().SetBulletVariables(springTwo, gunEnd);

                //Transform Position
                springOne.transform.position = new Vector2(gunEnd.transform.position.x, gunEnd.transform.position.y);
                springTwo.transform.position = gunEnd.transform.position;
                springOne.transform.rotation = gunEnd.transform.rotation;
                springTwo.transform.rotation = gunEnd.transform.rotation;

                //Force Generator
                springOne.GetComponent <Bullets>().isForceGen = true;
                ForceGenerator2D springGenerator = forceManager.CreateSpringForceGenerator(springOne, springTwo, 1.0f, 10.0f);
                forceManager.AddForceGenerator(springGenerator);
                springOne.GetComponent <Bullets>().forceGen = springGenerator;

                springOne.GetComponent <Bullets>().isForceGen = true;
                ForceGenerator2D BouyancyGenerator = forceManager.CreateBouyancyForceGenerator(springOne, (waterSprite.transform.localScale.y) / 2.0f, 75.0f, 5.0f, -(waterSprite.transform.localScale.y) / 2.0f);
                forceManager.AddForceGenerator(BouyancyGenerator);
                springOne.GetComponent <Bullets>().forceGen = BouyancyGenerator;

                break;

            case 3:     //Rod
                Debug.Log("Rod");

                //Set Value
                int numRods = 1;

                //Particle Link
                GameObject     particleLinkRod  = new GameObject("ParticleLink"); // Don't forget to make the rod u dumb dumb
                Particle2DLink tempParticleLink = particleLinkRod.AddComponent <Particle2DLink>();
                particleLink = tempParticleLink;

                //Create Bullets
                GameObject rodOne = Instantiate(rodBullet);
                rodOne.name = "Rod" + numRods;
                numRods++;
                GameObject rodTwo = Instantiate(rodBullet);
                rodTwo.name = "Rod" + numRods;
                numRods++;

                //Set Variables
                rodOne.GetComponent <Bullets>().SetBulletVariables(rodOne, gunEnd);
                rodTwo.GetComponent <Bullets>().SetBulletVariables(rodTwo, gunEnd);

                //Transform Position
                rodOne.transform.position = new Vector2(gunEnd.transform.position.x, gunEnd.transform.position.y + 1.0f);     //Change y so it doesn't spawn on top of each other
                rodTwo.transform.position = gunEnd.transform.position;
                rodOne.transform.rotation = gunEnd.transform.rotation;
                rodTwo.transform.rotation = gunEnd.transform.rotation;

                //Particle Link
                rodOne.GetComponent <Bullets>().isParticleLink = true;
                Particle2DLink link = particleLink.CreateLink(rodOne, rodTwo, 1.0f);
                rodOne.GetComponent <Bullets>().particleLink = link;

                //Force Generator
                rodOne.GetComponent <Bullets>().isForceGen = true;
                ForceGenerator2D BouyancyGen = forceManager.CreateBouyancyForceGenerator(rodOne, (waterSprite.transform.localScale.y) / 2.0f, 75.0f, 5.0f, -(waterSprite.transform.localScale.y) / 2.0f);
                forceManager.AddForceGenerator(BouyancyGen);
                rodOne.GetComponent <Bullets>().forceGen = BouyancyGen;

                break;
            }
        }
    }