Exemplo n.º 1
0
    void Shoot()
    {
        Vector2 direction = targetGameObject.transform.position - transform.position;

        direction.Normalize();

        GameObject spawnedProjectile = projectileSpawn.CreateProjectile();

        spawnedProjectile.transform.position = (Vector2)transform.position + direction * RelativeShootingDistanceFromShip;
        spawnedProjectile.transform.rotation = transform.rotation;
        Rigidbody2D projectileRigidbody = spawnedProjectile.GetComponent <Rigidbody2D>();

        projectileRigidbody.AddForce(direction * ProjectileSpeed);
        lastTimeOfFiring = Time.time;
    }
Exemplo n.º 2
0
    void Shoot()
    {
        Vector2 mousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        Vector2 direction     = Camera.main.ScreenToWorldPoint(mousePosition) - transform.position;

        direction.Normalize();

        GameObject spawnedProjectile = projectileSpawn.CreateProjectile();

        spawnedProjectile.transform.position = (Vector2)transform.position + direction * RelativeShootingDistanceFromShip;
        spawnedProjectile.transform.rotation = transform.rotation;

        Rigidbody2D projectileRigidbody = spawnedProjectile.GetComponent <Rigidbody2D> ();

        projectileRigidbody.AddForce(direction * ProjectileSpeed);
        lastTimeOfFiring = Time.time;
    }