void CmdShootRequest(Vector3 pos) { projectiles bul = Instantiate <projectiles>(bullet, pos, Quaternion.identity) as projectiles; bul.fire(transform); NetworkServer.Spawn(bul.gameObject); }
//public GameObject singleTargetProjectile; public void fire(List <invader> invader, attack attack, Transform origin, GameObject appearance) { if (invader.Count >= 1) { if (invader[0].gameObject.activeInHierarchy) { GameObject newProjectile = Instantiate(appearance, new Vector2(origin.position.x, origin.position.y), Quaternion.identity) as GameObject; projectiles projectile = newProjectile.GetComponent <projectiles>(); projectile.target = invader[0].transform; projectile.attack = attack; } } }
void OnTriggerEnter2D(Collider2D col) { //gets hurt by main character projectile projectiles shot = col.gameObject.GetComponent <projectiles>(); if (shot != null)//if shot { if (shot.isEnemyShot != isEnemy) { Damage(shot.damage); //calling function Destroy(shot.gameObject); //calling function } } }
//-------------------------------- // 3 - Shooting from another script //-------------------------------- /// <summary> /// Create a new projectile if possible /// </summary> public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; // Create a new shot var shotTransform = Instantiate(shotPrefab) as Transform; // Assign position shotTransform.position = transform.position; // The is enemy property projectiles shot = shotTransform.gameObject.GetComponent <projectiles>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // Make the weapon shot always towards it Move move = shotTransform.gameObject.GetComponent <Move>(); CharacterMovement facingDirection = GetComponent <CharacterMovement>(); if (move != null) { if (facingDirection.facingRight) { move.direction = this.transform.right; // towards in 2D space is the right of the sprite } else { move.direction = this.transform.right * -1; shot.transform.Rotate(0, 0, -180.0f); } } } }