public void Detach() { if (IsAttached) { AttachedTo.Detach(this); } }
void Start() { if (AttachedTo != null && !AttachedTo.Every.Contains(gameObject)) { AttachedTo.Attach(gameObject); } }
/// <summary> /// Determines what happens when other object get "out of sight" from enemy. /// </summary> /// <param name="collider">A Collider.</param> /// <param name="other">A GameObject.</param> /// <param name="side">An enum Side.(Used to check objects side)</param> public void OnPlayerOutOfSight(Collider collider, GameObject other, Side side) { if (other.Transform == target) { state = EnemyState.GoingHome; target = null; AttachedTo.GetComponent("AttackRange").Enabled = false; } }
/// <summary> /// Determines what happens when enemy notice other object. /// </summary> /// <param name="collider">A Collider.</param> /// <param name="other">A GameObject.</param> /// <param name="side">An enum Side.(Used to check objects side)</param> public void OnPlayerInSight(Collider collider, GameObject other, Side side) { if (other.Tag == Tag.Player) { state = EnemyState.Aggro; target = other.Transform; AttachedTo.GetComponent("AttackRange").Enabled = true; } }
public override void UpdateFunc() { if (AttachedTo != null) { AttachedTo.MoveNode(Trans.forward * Force * Time.deltaTime); } Model.Rotate(new Vector3(0, 0, -Force * Time.deltaTime * 2000), Space.Self); }
public override void UpdateFunc() { if (AttachedTo != null && AttachedTo.FixedPosition == false) { Vector3 vec = AttachedTo.Position - AttachedTo.LastPosition; float speedFactor = Mathf.Pow(vec.magnitude / Time.deltaTime, 2); float angleFactor = Vector3.Dot(vec.normalized, Trans.up); AttachedTo.MoveNode(Trans.up * Drag * speedFactor * -angleFactor * Time.deltaTime); } }
/// <summary> /// Updates the current animation and sets the sprite for the SpriteRenderer. /// </summary> /// <param name="deltaTime">Time in milliseconds since last update.</param> public void Update(double deltaTime) { if (currentAnimation != null) { currentAnimation.Update(deltaTime); if (!currentAnimation.Done) { AttachedTo.GetComponent <SpriteRenderer>().Sprite = currentAnimation.GetCurrentFrameSprite(); } } }
/// <summary> /// Update EnemyMovement. /// </summary> /// <param name="deltaTime">Time in milliseconds since last update</param> public override void Update(double deltaTime) { if (rigidBody == null) { rigidBody = AttachedTo.GetComponent <RigidBody>(); } if (animator == null) { animator = AttachedTo.GetComponent <Animator>(); } float speed = walkSpeed * (float)deltaTime; if (state == EnemyState.Attacking) { if (animator.GetCurrentAnimation().Done) { state = EnemyState.Aggro; animator.GetCurrentAnimation().Reset(); } } else if (state == EnemyState.Home) { if (distanceTravelled < maxDistance) { Walk(direction > 0, speed); distanceTravelled += Math.Abs(rigidBody.Velocity.X); } else { direction *= -1; distanceTravelled = 0; } } else if (state == EnemyState.Aggro) { Walk(target.Position.X >= AttachedTo.Transform.Position.X, speed); } else if (state == EnemyState.GoingHome) { if (!((Enemy)AttachedTo).IsHome) { Walk(((Enemy)AttachedTo).HomePos.X >= AttachedTo.Transform.Position.X, speed); } else { state = EnemyState.Home; } } }
/// <summary> /// Determines what happens when other object walks. /// </summary> /// <param name="right">A bool(used to get enemies direction).</param> /// <param name="speed">A float for movement speed.</param> private void Walk(bool right, float speed) { animator.ChangeAnimation("walk"); if (right && rigidBody.Velocity.X + speed < maxWalkSpeed) { AttachedTo.GetComponent <SpriteRenderer>().SpriteEffect = SpriteEffects.None; rigidBody.Velocity += new Vector2(1, 0) * speed; } else if (!right && rigidBody.Velocity.X - speed > -maxWalkSpeed) { AttachedTo.GetComponent <SpriteRenderer>().SpriteEffect = SpriteEffects.FlipHorizontally; rigidBody.Velocity += new Vector2(-1, 0) * speed; } }
/// <summary> /// Checks if this item could be stored (traits etc.) without considering size /// </summary> /// <param name="item"></param> /// <returns></returns> public bool CouldStoreItem(Item item) { // Do not store if the item is the container itself if (AttachedTo.GetComponent <Item>() == item) { return(false); } foreach (Filter filter in Filters) { if (!filter.CanStore(item)) { return(false); } } return(true); }
public static GameInput Get(this AttachedTo inputAttached) { switch (inputAttached) { case AttachedTo.Keyboard: return(Keyboard); case AttachedTo.ControllerOne: return(ControllerOne); case AttachedTo.ControllerTwo: return(ControllerTwo); case AttachedTo.ControllerThree: return(ControllerThree); case AttachedTo.ControllerFour: return(ControllerFour); default: throw new Exception("Kind of input not found."); } }
/// <summary> /// Update PlayerMovement. /// </summary> /// <param name="deltaTime">Time in milliseconds since last update</param> public override void Update(double deltaTime) { if (rigidBody == null) { rigidBody = AttachedTo.GetComponent <RigidBody>(); } if (animator == null) { animator = AttachedTo.GetComponent <Animator>(); } float speed = walkSpeed * (float)deltaTime; // ATTKACK if (!attacking && InputManager.IsKeyJustPressed(Keys.Z)) { attacking = true; animator.ChangeAnimation("attack"); } else if (attacking && animator.GetCurrentAnimation().Done) { attacking = false; } else if (!attacking) { isRunning = InputManager.IsKeyPressed(Keys.LeftShift); // Walk if (InputManager.IsKeyPressed(Keys.Right)) { AttachedTo.GetComponent <SpriteRenderer>().SpriteEffect = SpriteEffects.None; if (canJump && isRunning) { rigidBody.Velocity += new Vector2(1, 0) * speed * runBoost; } else if (rigidBody.Velocity.X + speed < maxWalkSpeed) { rigidBody.Velocity += new Vector2(1, 0) * speed; } if (canJump) { if (rigidBody.Velocity.X > maxWalkSpeed) { animator.ChangeAnimation("run"); } else { animator.ChangeAnimation("walk"); } } } if (InputManager.IsKeyPressed(Keys.Left)) { AttachedTo.GetComponent <SpriteRenderer>().SpriteEffect = SpriteEffects.FlipHorizontally; if (canJump && isRunning) { rigidBody.Velocity += new Vector2(-1, 0) * speed * runBoost; } else if (rigidBody.Velocity.X - speed > -maxWalkSpeed) { rigidBody.Velocity += new Vector2(-1, 0) * speed; } if (canJump) { if (rigidBody.Velocity.X < -maxWalkSpeed) { animator.ChangeAnimation("run"); } else { animator.ChangeAnimation("walk"); } } } // Jump if (canJump && InputManager.IsKeyJustPressed(Keys.Up) && rigidBody.Velocity.Y < 0.1f) { rigidBody.Velocity += new Vector2(0, -0.3f) * (float)deltaTime; canJump = false; } if (!canJump) { rigidBody.Velocity *= new Vector2(0.99f, 1f); animator.ChangeAnimation("jump"); } else if (rigidBody.Velocity.LengthSquared() <= 0.8f) { animator.ChangeAnimation("idle"); } //////////////////////////////// //if (InputManager.IsKeyPressed(Keys.RightShift)) // AttachedTo.Transform.Translate(AttachedTo.Transform.Forward * speed * (float)deltaTime); if (InputManager.IsKeyPressed(Keys.PageDown)) { AttachedTo.Transform.Rotation -= speed * 5; } if (InputManager.IsKeyPressed(Keys.PageUp)) { AttachedTo.Transform.Rotation += speed * 5; } ////////////////////////////////// } }
public Player GetControllerOfACardThisIsAttachedTo() { return(AttachedTo == null ? Controller : AttachedTo.GetControllerOfACardThisIsAttachedTo()); }