private void circleDamage() { if (DamageCircle.IsOutsideCircle_Static(GameObject.Find("Player").transform.position)) { currentHealth -= 10; healthBar.SetHealth(currentHealth); if (facing == 1.0f) { if (currentHealth <= 0) { animator.SetBool("Dead_R", true); player_dead = true; } else { animator.SetTrigger("Hurt_R"); } } else if (facing == -1.0f) { if (currentHealth <= 0) { animator.SetBool("Dead_L", true); player_dead = true; } else { animator.SetTrigger("Hurt_L"); } } } }
// Use this for initialization private void Start() { character = new Character(); character.SetEquippedBodyArmor(Character.BodyArmor.Tier_2); characterWindow.SetCharacter(character); FunctionPeriodic.Create(() => { if (DamageCircle.IsOutsideCircle_Static(GetPosition())) { character.Damage(4); } }, .1f); V_Object vObject = CreateBasicUnit(transform, new Vector3(500, 680), 30f, GameAssets.i.m_MarineSpriteSheet); V_UnitAnimation unitAnimation = vObject.GetLogic <V_UnitAnimation>(); V_UnitSkeleton unitSkeleton = vObject.GetLogic <V_UnitSkeleton>(); V_IObjectTransform objectTransform = vObject.GetLogic <V_IObjectTransform>(); bool canShoot = true; V_UnitSkeleton_Composite_Weapon unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, GameAssets.UnitAnimEnum.dMarine_AimWeaponRight, GameAssets.UnitAnimEnum.dMarine_AimWeaponRightInvertV, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRight, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRightInvertV); vObject.AddRelatedObject(unitSkeletonCompositeWeapon); unitSkeletonCompositeWeapon.SetActive(); V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_BodyHead = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "Body", "Head" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_BodyHead); V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_Feet = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "FootL", "FootR" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_Feet); FunctionUpdater.Create(() => { Vector3 targetPosition = UtilsClass.GetMouseWorldPosition(); Vector3 aimDir = (targetPosition - vObject.GetPosition()).normalized; // Check for hits Vector3 gunEndPointPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash"); RaycastHit2D raycastHit = Physics2D.Raycast(gunEndPointPosition, (targetPosition - gunEndPointPosition).normalized, Vector3.Distance(gunEndPointPosition, targetPosition)); if (raycastHit.collider != null) { // Hit something targetPosition = raycastHit.point; } unitSkeletonCompositeWeapon.SetAimTarget(targetPosition); if (canShoot && Input.GetMouseButton(0)) { // Shoot canShoot = false; // Replace Body and Head with Attack unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dMarine_Attack.GetUnitAnim(aimDir), "Body", "Head"); // Shoot Composite Skeleton unitSkeletonCompositeWeapon.Shoot(targetPosition, () => { canShoot = true; }); // Add Effects Vector3 shootFlashPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash"); if (OnShoot != null) { OnShoot(this, new OnShootEventArgs { gunEndPointPosition = shootFlashPosition, shootPosition = targetPosition }); } //Shoot_Flash.AddFlash(shootFlashPosition); //WeaponTracer.Create(shootFlashPosition, targetPosition); } // Manual Movement bool isMoving = false; Vector3 moveDir = new Vector3(0, 0); if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { moveDir.y = +1; isMoving = true; } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { moveDir.y = -1; isMoving = true; } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { moveDir.x = -1; isMoving = true; } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { moveDir.x = +1; isMoving = true; } moveDir.Normalize(); float moveSpeed = 50f; Vector3 targetMoveToPosition = objectTransform.GetPosition() + moveDir * moveSpeed * Time.deltaTime; // Test if can move there raycastHit = Physics2D.Raycast(GetPosition() + moveDir * .1f, moveDir, Vector3.Distance(GetPosition(), targetMoveToPosition)); if (raycastHit.collider != null) { // Hit something } else { // Can move, no wall objectTransform.SetPosition(targetMoveToPosition); } if (isMoving) { Dirt_Handler.SpawnInterval(GetPosition() + new Vector3(0, -4f), moveDir * -1f); } // Update Feet unitSkeletonCompositeWalker_Feet.UpdateBodyParts(isMoving, moveDir); if (canShoot) { // Update Head and Body parts only when Not Shooting unitSkeletonCompositeWalker_BodyHead.UpdateBodyParts(isMoving, aimDir); } }); }