-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class Demo2DJumpAndRun : MonoBehaviour | ||
{ | ||
void OnJoinedRoom() | ||
{ | ||
if( PhotonNetwork.isMasterClient == false ) | ||
{ | ||
return; | ||
} | ||
|
||
PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 5.5f, 0 ), Quaternion.identity, 0, null ); | ||
PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 4.5f, 0 ), Quaternion.identity, 0, null ); | ||
PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 3.5f, 0 ), Quaternion.identity, 0, null ); | ||
|
||
PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 5.5f, 0 ), Quaternion.identity, 0, null ); | ||
PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 4.5f, 0 ), Quaternion.identity, 0, null ); | ||
PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 3.5f, 0 ), Quaternion.identity, 0, null ); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class JumpAndRunMovement : MonoBehaviour | ||
{ | ||
public float Speed; | ||
public float JumpForce; | ||
|
||
Animator m_Animator; | ||
Rigidbody2D m_Body; | ||
PhotonView m_PhotonView; | ||
|
||
bool m_IsGrounded; | ||
|
||
void Awake() | ||
{ | ||
m_Animator = GetComponent<Animator>(); | ||
m_Body = GetComponent<Rigidbody2D>(); | ||
m_PhotonView = GetComponent<PhotonView>(); | ||
} | ||
|
||
void Update() | ||
{ | ||
UpdateIsGrounded(); | ||
UpdateIsRunning(); | ||
UpdateFacingDirection(); | ||
} | ||
|
||
void FixedUpdate() | ||
{ | ||
if( m_PhotonView.isMine == false ) | ||
{ | ||
return; | ||
} | ||
|
||
UpdateMovement(); | ||
UpdateJumping(); | ||
} | ||
|
||
void UpdateFacingDirection() | ||
{ | ||
if( m_Body.velocity.x > 0.2f ) | ||
{ | ||
transform.localScale = new Vector3( 1, 1, 1 ); | ||
} | ||
else if( m_Body.velocity.x < -0.2f ) | ||
{ | ||
transform.localScale = new Vector3( -1, 1, 1 ); | ||
} | ||
} | ||
|
||
void UpdateJumping() | ||
{ | ||
if (Input.GetButton("Jump") && m_IsGrounded) | ||
{ | ||
m_Animator.SetTrigger("IsJumping"); | ||
m_Body.AddForce(Vector2.up * JumpForce); | ||
m_PhotonView.RPC("DoJump", PhotonTargets.Others); | ||
} | ||
} | ||
|
||
[PunRPC] | ||
void DoJump() | ||
{ | ||
m_Animator.SetTrigger( "IsJumping" ); | ||
} | ||
|
||
void UpdateMovement() | ||
{ | ||
Vector2 movementVelocity = m_Body.velocity; | ||
|
||
if( Input.GetAxisRaw( "Horizontal" ) > 0.5f ) | ||
{ | ||
movementVelocity.x = Speed; | ||
|
||
} | ||
else if( Input.GetAxisRaw( "Horizontal" ) < -0.5f ) | ||
{ | ||
movementVelocity.x = -Speed; | ||
} | ||
else | ||
{ | ||
movementVelocity.x = 0; | ||
} | ||
|
||
m_Body.velocity = movementVelocity; | ||
} | ||
|
||
void UpdateIsRunning() | ||
{ | ||
m_Animator.SetBool( "IsRunning", Mathf.Abs( m_Body.velocity.x ) > 0.1f ); | ||
} | ||
|
||
void UpdateIsGrounded() | ||
{ | ||
Vector2 position = new Vector2( transform.position.x, transform.position.y ); | ||
|
||
//RaycastHit2D hit = Physics2D.Raycast( position, -Vector2.up, 0.1f, 1 << LayerMask.NameToLayer( "Ground" ) ); | ||
RaycastHit2D hit = Physics2D.Raycast(position, -Vector2.up, 0.1f); | ||
|
||
m_IsGrounded = hit.collider != null; | ||
m_Animator.SetBool( "IsGrounded", m_IsGrounded ); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.