Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        ProjectilePosition   = GameObject.Find("ReloadPosition").GetComponent <Transform>();
        RopeEnd              = GameObject.Find("Seg6");
        RopeEndJoint         = RopeEnd.GetComponent <FixedJoint2D>();
        gameControllerScript = GameObject.Find("GameControllerScript").GetComponent <GameControllerScript>();

        launched         = true;
        coroutineTrigger = true;
        ejected          = false;
        FlyingSound      = GetComponent <AudioSource>();
    }
Example #2
0
    void EjectReload()
    {
        if (launched == true)
        {
            Projectile           = Instantiate(ProjectilePrefab, ProjectilePosition.position, ProjectilePosition.rotation);
            RopeEndJoint.enabled = true;
            RopeEnd.GetComponent <FixedJoint2D>().connectedBody = Projectile.GetComponent <Rigidbody2D>();
            ejected          = false;
            launched         = false;
            coroutineTrigger = true;
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                RopeEndJoint.enabled = false;
                if (ejected == false)
                {
                    if (Projectile.GetComponent <Rigidbody2D>().velocity.x > 0)
                    {
                        Projectile.GetComponent <Rigidbody2D>().AddForce(transform.right *
                                                                         (Projectile.GetComponent <Rigidbody2D>().velocity.x * 20));
                    }

                    if (Projectile.GetComponent <Rigidbody2D>().velocity.y > 0)
                    {
                        Projectile.GetComponent <Rigidbody2D>().AddForce(transform.up *
                                                                         (Projectile.GetComponent <Rigidbody2D>().velocity.y * 20));
                    }
                    ejected = true;

                    FlyingSound.Play();
                }
                if (coroutineTrigger == true)
                {
                    StartCoroutine(AutoReload());
                }
            }
        }
    }