Skip to content
Snippets Groups Projects
Commit 6452f628 authored by Graham Solie's avatar Graham Solie
Browse files
parents 3fe70388 803ac1df
No related branches found
No related tags found
No related merge requests found
No preview for this file type
fileFormatVersion: 2
guid: bb1056459d1870245989ac7c1ad96539
timeCreated: 1479756883
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class InBetween : MonoBehaviour {
private Rigidbody2D Player;
private Animator myAnimator;
[SerializeField]
private float speed;
private bool LookRight = true;
private bool canMove = true;
private bool canJump = true;
// Use this for initialization
void Start()
{
Player = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>(); //required for animation *******
}
// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float i = Input.GetAxis("Vertical");
Movement(h);
FlipPlayer(h);
RotatePlayerZaxis(h);
Jump();
}
//controlling the characters movement
private void Movement(float horizontal)
{
if (canMove)
{
Player.velocity = new Vector2(speed * horizontal, Player.velocity.y);
myAnimator.SetFloat("speed", (Mathf.Abs(horizontal))); //required for animation *******
}
}
private void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) && canJump)
{
canJump = false;
Player.AddForce(new Vector2(0, 600));
}
}
//faces the characters body in the appropriate direction
private void FlipPlayer(float horizontal)
{
if (horizontal > 0 && !LookRight || horizontal < 0 && LookRight)
{
LookRight = !LookRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
//keeps the character from falling over
private void RotatePlayerZaxis(float horizonal)
{
Vector3 myRotation = gameObject.transform.rotation.eulerAngles;
Vector3 Pos = transform.localPosition;
//if the player does not need to be climbing up an angle, the character will be fixed upright
if (Pos.x < -4f || Pos.x > 5f)
{
transform.localRotation = Quaternion.Euler(0, 0, 0);
}
else
{
//allows the character to rotate but not past 90 degrees either direction when climbing
if (myRotation.z > 90)
{
myRotation.z = Mathf.Clamp(0, 0, 0);
transform.rotation = Quaternion.Euler(myRotation);
}
if (myRotation.z < -90)
{
myRotation.z = Mathf.Clamp(0, 0, 0);
transform.rotation = Quaternion.Euler(myRotation);
}
}
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "ground")
{
canJump = true;
}
}
}
\ No newline at end of file
using UnityEngine;
using System.Collections;
public class RandomPlatforms : MonoBehaviour {
GameObject platform;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment