本文整理汇总了C#中Door.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Door.GetComponent方法的具体用法?C# Door.GetComponent怎么用?C# Door.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Door
的用法示例。
在下文中一共展示了Door.GetComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
private void Update()
{
switch (state)
{
case State.Normal:
{
body.Move(IsIgnoringOneWayPlatforms);
float verticalAxis = Input.GetAxisRaw("Vertical");
float horizontalAxis = Input.GetAxisRaw("Horizontal");
// Snap values for analog sticks.
if (verticalAxis < 0)
{
verticalAxis = -1;
}
else if (verticalAxis > 0)
{
verticalAxis = 1;
}
if (horizontalAxis < 0)
{
horizontalAxis = -1;
}
else if (horizontalAxis > 0)
{
horizontalAxis = 1;
}
if (body.IsGrounded)
{
if (verticalAxis > 0)
{
animator.Play(Animator.StringToHash("AimUp"));
}
else if (verticalAxis < 0)
{
animator.Play(Animator.StringToHash("AimDown"));
}
}
if (verticalAxis == 0)
{
// Horizontal acceleration.
body.velocity.x += horizontalAxis * accelerationX * Time.deltaTime;
body.velocity.x = Mathf.Clamp(body.velocity.x, -maxVelocityX, maxVelocityX);
}
if (horizontalAxis != 0)
{
body.DirectionX = horizontalAxis;
}
// Jumping.
if (body.IsGrounded && Input.GetButtonDown("Jump") && verticalAxis >= 0)
{
body.velocity.y = jumpVelocityY;
}
// Jump down from one-way platforms.
ignoreOneWayPlatformsTimer -= Time.deltaTime;
if (!IsIgnoringOneWayPlatforms && Input.GetButton("Jump") && verticalAxis < 0)
{
IgnoreOneWayPlatforms();
}
// Reduce jump height when "Jump" is not pressed.
if (body.velocity.y > 0 && !Input.GetButton("Jump"))
{
body.velocity.y += jumpReductionVelocityY;
}
// Open a door.
if (body.IsGrounded && verticalAxis > 0)
{
Collider2D doorCollider = Physics2D.OverlapArea(boxCollider.bounds.min, boxCollider.bounds.max, 1 << LayerMask.NameToLayer("Door"));
if (doorCollider)
{
door = doorCollider.GetComponent<Door>();
if (door.isClosed)
{
body.velocity.x = 0;
state = State.OpenDoor;
openDoorTimer = 0;
animator.Play(Animator.StringToHash("OpenDoor"));
}
else
{
if (door.GetComponent<ExitDoor>())
{
animator.Play(Animator.StringToHash("OpenDoor"));
Kill();
}
}
}
}
if (verticalAxis == 0)
{
if (body.IsGrounded && body.velocity.x != 0)
{
//.........这里部分代码省略.........
示例2: ReplaceComponent
protected static void ReplaceComponent(Door door)
{
if (door.GetComponent<DoorPortalComponentEx>() != null) return;
if (door.GetComponent<Turnstile.TurnstileDoorPortalComponent>() != null) return;
if (door.GetComponent<MysteriousDeviceDoor.MysteriousDoorPortalComponent>() != null) return;
Door.DoorPortalComponent oldComponent = door.PortalComponent as Door.DoorPortalComponent;
door.RemoveComponent<Door.DoorPortalComponent>();
ObjectComponents.AddComponent<DoorPortalComponentEx>(door, new object[0]);
if (oldComponent != null)
{
Door.DoorPortalComponent newComponent = door.PortalComponent as Door.DoorPortalComponent;
if (newComponent != null)
{
newComponent.OwnerDoor = oldComponent.OwnerDoor;
}
}
}