I wanna be a fox first commit.

Initial commit. Complete project for 'I Wanna Be A Fox' - a 2D scrolling game inspired by 'I Wanna Be The Guy'.
This commit is contained in:
2024-02-22 07:27:59 +09:00
commit a80f3d6560
688 changed files with 102537 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BGMControler : MonoBehaviour {
// Use this for initialization
public GameObject Sound;
private void Awake()
{
if (Sound)
{
DontDestroyOnLoad(this.gameObject);
}
}
void Start () {
}
// Update is called once per frame
void Update () {
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ba444a7643bc504e9e5544a6780d687
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+116
View File
@@ -0,0 +1,116 @@
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour
{
public Controller2D target;
public float verticalOffset;
public float lookAheadDstX;
public float lookSmoothTimeX;
public float verticalSmoothTime;
public Vector2 focusAreaSize;
FocusArea focusArea;
float currentLookAheadX;
float targetLookAheadX;
float lookAheadDirX;
float smoothLookVelocityX;
float smoothVelocityY;
bool lookAheadStopped;
void Start()
{
focusArea = new FocusArea(target.thisCollider.bounds, focusAreaSize);
}
void LateUpdate()
{
focusArea.Update(target.thisCollider.bounds);
Vector2 focusPosition = focusArea.centre + Vector2.up * verticalOffset;
if (focusArea.velocity.x != 0)
{
lookAheadDirX = Mathf.Sign(focusArea.velocity.x);
if (Mathf.Sign(target.playerInput.x) == Mathf.Sign(focusArea.velocity.x) && target.playerInput.x != 0)
{
lookAheadStopped = false;
targetLookAheadX = lookAheadDirX * lookAheadDstX;
}
else
{
if (!lookAheadStopped)
{
lookAheadStopped = true;
targetLookAheadX = currentLookAheadX + (lookAheadDirX * lookAheadDstX - currentLookAheadX) / 4f;
}
}
}
currentLookAheadX = Mathf.SmoothDamp(currentLookAheadX, targetLookAheadX, ref smoothLookVelocityX, lookSmoothTimeX);
focusPosition.y = Mathf.SmoothDamp(transform.position.y, focusPosition.y, ref smoothVelocityY, verticalSmoothTime);
focusPosition += Vector2.right * currentLookAheadX;
transform.position = (Vector3)focusPosition + Vector3.forward * -10;
}
void OnDrawGizmos()
{
Gizmos.color = new Color(1, 0, 0, .5f);
Gizmos.DrawCube(focusArea.centre, focusAreaSize);
}
struct FocusArea
{
public Vector2 centre;
public Vector2 velocity;
float left, right;
float top, bottom;
public FocusArea(Bounds targetBounds, Vector2 size)
{
left = targetBounds.center.x - size.x / 2;
right = targetBounds.center.x + size.x / 2;
bottom = targetBounds.min.y;
top = targetBounds.min.y + size.y;
velocity = Vector2.zero;
centre = new Vector2((left + right) / 2, (top + bottom) / 2);
}
public void Update(Bounds targetBounds)
{
float shiftX = 0;
if (targetBounds.min.x < left)
{
shiftX = targetBounds.min.x - left;
}
else if (targetBounds.max.x > right)
{
shiftX = targetBounds.max.x - right;
}
left += shiftX;
right += shiftX;
float shiftY = 0;
if (targetBounds.min.y < bottom)
{
shiftY = targetBounds.min.y - bottom;
}
else if (targetBounds.max.y > top)
{
shiftY = targetBounds.max.y - top;
}
top += shiftY;
bottom += shiftY;
centre = new Vector2((left + right) / 2, (top + bottom) / 2);
velocity = new Vector2(shiftX, shiftY);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c9e82b0126612b949ace711bf0faab2c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+258
View File
@@ -0,0 +1,258 @@
using UnityEngine;
using System.Collections;
public class Controller2D : RaycastController
{
float maxClimbAngle = 80;
float maxDescendAngle = 80;
public CollisionInfo collisions;
[HideInInspector]
public Vector2 playerInput;
public override void Start()
{
base.Start();
collisions.faceDir = 1;
}
public void Move(Vector3 velocity, bool standingOnPlatform)
{
Move(velocity, Vector2.zero, standingOnPlatform);
}
public void Move(Vector3 velocity, Vector2 input, bool standingOnPlatform = false)
{
UpdateRaycastOrigins();
collisions.Reset();
collisions.velocityOld = velocity;
playerInput = input;
if (velocity.x != 0)
{
collisions.faceDir = (int)Mathf.Sign(velocity.x);
}
if (velocity.y < 0)
{
DescendSlope(ref velocity);
}
HorizontalCollisions(ref velocity);
if (velocity.y != 0)
{
VerticalCollisions(ref velocity);
}
transform.Translate(velocity);
if (standingOnPlatform)
{
collisions.below = true;
}
}
void HorizontalCollisions(ref Vector3 velocity)
{
float directionX = collisions.faceDir;
float rayLength = Mathf.Abs(velocity.x) + skinWidth;
if (Mathf.Abs(velocity.x) < skinWidth)
{
rayLength = 2 * skinWidth;
}
for (int i = 0; i < horizontalRayCount; i++)
{
Vector2 rayOrigin = (directionX == -1) ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight;
rayOrigin += Vector2.up * (horizontalRaySpacing * i);
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, collisionMask);
Debug.DrawRay(rayOrigin, Vector2.right * directionX * rayLength, Color.red);
if (hit)
{
if (hit.distance == 0)
{
continue;
}
float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
if (i == 0 && slopeAngle <= maxClimbAngle)
{
if (collisions.descendingSlope)
{
collisions.descendingSlope = false;
velocity = collisions.velocityOld;
}
float distanceToSlopeStart = 0;
if (slopeAngle != collisions.slopeAngleOld)
{
distanceToSlopeStart = hit.distance - skinWidth;
velocity.x -= distanceToSlopeStart * directionX;
}
ClimbSlope(ref velocity, slopeAngle);
velocity.x += distanceToSlopeStart * directionX;
}
if (!collisions.climbingSlope || slopeAngle > maxClimbAngle)
{
velocity.x = (hit.distance - skinWidth) * directionX;
rayLength = hit.distance;
if (collisions.climbingSlope)
{
velocity.y = Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x);
}
collisions.left = directionX == -1;
collisions.right = directionX == 1;
}
}
}
}
void VerticalCollisions(ref Vector3 velocity)
{
float directionY = Mathf.Sign(velocity.y);
float rayLength = Mathf.Abs(velocity.y) + skinWidth;
for (int i = 0; i < verticalRayCount; i++)
{
Vector2 rayOrigin = (directionY == -1) ? raycastOrigins.bottomLeft : raycastOrigins.topLeft;
rayOrigin += Vector2.right * (verticalRaySpacing * i + velocity.x);
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, rayLength, collisionMask);
Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.red);
if (hit)
{
if (hit.collider.tag == "Through")
{
if (directionY == 1 || hit.distance == 0)
{
continue;
}
if (collisions.fallingThroughPlatform)
{
continue;
}
if (playerInput.y == -1)
{
collisions.fallingThroughPlatform = true;
Invoke("ResetFallingThroughPlatform", .5f);
continue;
}
}
velocity.y = (hit.distance - skinWidth) * directionY;
rayLength = hit.distance;
if (collisions.climbingSlope)
{
velocity.x = velocity.y / Mathf.Tan(collisions.slopeAngle * Mathf.Deg2Rad) * Mathf.Sign(velocity.x);
}
collisions.below = directionY == -1;
collisions.above = directionY == 1;
}
}
if (collisions.climbingSlope)
{
float directionX = Mathf.Sign(velocity.x);
rayLength = Mathf.Abs(velocity.x) + skinWidth;
Vector2 rayOrigin = ((directionX == -1) ? raycastOrigins.bottomLeft : raycastOrigins.bottomRight) + Vector2.up * velocity.y;
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, collisionMask);
if (hit)
{
float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
if (slopeAngle != collisions.slopeAngle)
{
velocity.x = (hit.distance - skinWidth) * directionX;
collisions.slopeAngle = slopeAngle;
}
}
}
}
void ClimbSlope(ref Vector3 velocity, float slopeAngle)
{
float moveDistance = Mathf.Abs(velocity.x);
float climbVelocityY = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * moveDistance;
if (velocity.y <= climbVelocityY)
{
velocity.y = climbVelocityY;
velocity.x = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * moveDistance * Mathf.Sign(velocity.x);
collisions.below = true;
collisions.climbingSlope = true;
collisions.slopeAngle = slopeAngle;
}
}
void DescendSlope(ref Vector3 velocity)
{
float directionX = Mathf.Sign(velocity.x);
Vector2 rayOrigin = (directionX == -1) ? raycastOrigins.bottomRight : raycastOrigins.bottomLeft;
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, -Vector2.up, Mathf.Infinity, collisionMask);
if (hit)
{
float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
if (slopeAngle != 0 && slopeAngle <= maxDescendAngle)
{
if (Mathf.Sign(hit.normal.x) == directionX)
{
if (hit.distance - skinWidth <= Mathf.Tan(slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x))
{
float moveDistance = Mathf.Abs(velocity.x);
float descendVelocityY = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * moveDistance;
velocity.x = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * moveDistance * Mathf.Sign(velocity.x);
velocity.y -= descendVelocityY;
collisions.slopeAngle = slopeAngle;
collisions.descendingSlope = true;
collisions.below = true;
}
}
}
}
}
void ResetFallingThroughPlatform()
{
collisions.fallingThroughPlatform = false;
}
public struct CollisionInfo
{
public bool above, below;
public bool left, right;
public bool climbingSlope;
public bool descendingSlope;
public float slopeAngle, slopeAngleOld;
public Vector3 velocityOld;
public int faceDir;
public bool fallingThroughPlatform;
public void Reset()
{
above = below = false;
left = right = false;
climbingSlope = false;
descendingSlope = false;
slopeAngleOld = slopeAngle;
slopeAngle = 0;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3650d2147dc64f04e8c49494742b4f38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+41
View File
@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class MapTriger : MonoBehaviour {
public UnityEvent TrigerOnEvent;
public float TrigerSizeX = 0.1f;
public float TrigerSizeY = 1.0f;
[SerializeField] private Transform Player;
[SerializeField] private Transform ThisTriger;
int counter = 0;
private void Awake()
{
if (TrigerOnEvent == null)
TrigerOnEvent = new UnityEvent();
}
void Update () {
if (Mathf.Abs(Player.position.x-ThisTriger.position.x)<=TrigerSizeX/2 && Mathf.Abs(Player.position.y - ThisTriger.position.y) <= TrigerSizeY/2 && counter < 1)
{
TrigerOnEvent.Invoke();
counter++;
}
}
//Preview-------------------------------------------------------------
void OnDrawGizmos()
{
Gizmos.color = Color.blue;
Vector3 globalWaypointPos = new Vector3(ThisTriger.position.x, ThisTriger.position.y, 0);
Gizmos.DrawLine(globalWaypointPos - Vector3.up * TrigerSizeY/2 - Vector3.left * TrigerSizeX / 2, globalWaypointPos + Vector3.up * TrigerSizeY/2 - Vector3.left * TrigerSizeX / 2);
Gizmos.DrawLine(globalWaypointPos - Vector3.up * TrigerSizeY/2 + Vector3.left * TrigerSizeX / 2, globalWaypointPos + Vector3.up * TrigerSizeY/2 + Vector3.left * TrigerSizeX / 2);
Gizmos.DrawLine(globalWaypointPos - Vector3.left * TrigerSizeX / 2 - Vector3.up * TrigerSizeY / 2, globalWaypointPos + Vector3.left * TrigerSizeX/2 - Vector3.up * TrigerSizeY / 2);
Gizmos.DrawLine(globalWaypointPos - Vector3.left * TrigerSizeX / 2 + Vector3.up * TrigerSizeY / 2, globalWaypointPos + Vector3.left * TrigerSizeX / 2 + Vector3.up * TrigerSizeY / 2);
}
//Preview-------------------------------------------------------------
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20cef69cce25b4848b73ef92f9fecd96
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+49
View File
@@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class MapTrigerLevel2 : MonoBehaviour {
public UnityEvent TrigerOnEvent;
public float TrigerSizeX = 0.1f;
public float TrigerSizeY = 1.0f;
[SerializeField] private Transform Player;
[SerializeField] private Transform ThisTriger;
int counter = 1;
private void Awake()
{
if (TrigerOnEvent == null)
TrigerOnEvent = new UnityEvent();
}
void Update()
{
if (Mathf.Abs(Player.position.x - ThisTriger.position.x) <= TrigerSizeX / 2 && Mathf.Abs(Player.position.y - ThisTriger.position.y) <= TrigerSizeY / 2 && counter < 1)
{
TrigerOnEvent.Invoke();
counter++;
}
}
public void EnableLevel2Triger()
{
counter = 0;
Gizmos.color = Color.yellow;
}
//Preview-------------------------------------------------------------
void OnDrawGizmos()
{
Gizmos.color = Color.gray;
Vector3 globalWaypointPos = new Vector3(ThisTriger.position.x, ThisTriger.position.y, 0);
Gizmos.DrawLine(globalWaypointPos - Vector3.up * TrigerSizeY / 2 - Vector3.left * TrigerSizeX / 2, globalWaypointPos + Vector3.up * TrigerSizeY / 2 - Vector3.left * TrigerSizeX / 2);
Gizmos.DrawLine(globalWaypointPos - Vector3.up * TrigerSizeY / 2 + Vector3.left * TrigerSizeX / 2, globalWaypointPos + Vector3.up * TrigerSizeY / 2 + Vector3.left * TrigerSizeX / 2);
Gizmos.DrawLine(globalWaypointPos - Vector3.left * TrigerSizeX / 2 - Vector3.up * TrigerSizeY / 2, globalWaypointPos + Vector3.left * TrigerSizeX / 2 - Vector3.up * TrigerSizeY / 2);
Gizmos.DrawLine(globalWaypointPos - Vector3.left * TrigerSizeX / 2 + Vector3.up * TrigerSizeY / 2, globalWaypointPos + Vector3.left * TrigerSizeX / 2 + Vector3.up * TrigerSizeY / 2);
}
//Preview-------------------------------------------------------------
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76de23ddfcf8f234da5b9e09b151e8aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+123
View File
@@ -0,0 +1,123 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlatformController : RaycastController
{
public LayerMask passengerMask;
public Vector3[] localWaypoints;
Vector3[] globalWaypoints;
public float speed;
public bool cyclic;
public float waitTime;
[Range(0, 2)]
public float easeAmount;
int fromWaypointIndex;
float percentBetweenWaypoints;
float nextMoveTime;
bool MoveBool = false;
Dictionary<Transform, Controller2D> passengerDictionary = new Dictionary<Transform, Controller2D>();
public override void Start()
{
base.Start();
globalWaypoints = new Vector3[localWaypoints.Length];
for (int i = 0; i < localWaypoints.Length; i++)
{
globalWaypoints[i] = localWaypoints[i] + transform.position;
}
}
public void DoMove()
{
MoveBool = true;
}
public void DoNotMove()
{
MoveBool = false;
}
void Update()
{
if(MoveBool == true)
{
UpdateRaycastOrigins();
Vector3 velocity = CalculatePlatformMovement();
transform.Translate(velocity);
}
}
float Ease(float x)
{
float a = easeAmount + 1;
return Mathf.Pow(x, a) / (Mathf.Pow(x, a) + Mathf.Pow(1 - x, a));
}
Vector3 CalculatePlatformMovement()
{
if (Time.time < nextMoveTime)
{
return Vector3.zero;
}
fromWaypointIndex %= globalWaypoints.Length;
int toWaypointIndex = (fromWaypointIndex + 1) % globalWaypoints.Length;
float distanceBetweenWaypoints = Vector3.Distance(globalWaypoints[fromWaypointIndex], globalWaypoints[toWaypointIndex]);
percentBetweenWaypoints += Time.deltaTime * speed / distanceBetweenWaypoints;
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
float easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
Vector3 newPos = Vector3.Lerp(globalWaypoints[fromWaypointIndex], globalWaypoints[toWaypointIndex], easedPercentBetweenWaypoints);
if (percentBetweenWaypoints >= 1)
{
percentBetweenWaypoints = 0;
fromWaypointIndex++;
if (!cyclic)
{
if (fromWaypointIndex >= globalWaypoints.Length - 1)
{
fromWaypointIndex = 0;
System.Array.Reverse(globalWaypoints);
}
}
nextMoveTime = Time.time + waitTime;
}
return newPos - transform.position;
}
void OnDrawGizmos()
{
if (localWaypoints != null)
{
Gizmos.color = Color.red;
float size = .3f;
for (int i = 0; i < localWaypoints.Length; i++)
{
Vector3 globalWaypointPos = (Application.isPlaying) ? globalWaypoints[i] : localWaypoints[i] + transform.position;
Gizmos.DrawLine(globalWaypointPos - Vector3.up * size, globalWaypointPos + Vector3.up * size);
Gizmos.DrawLine(globalWaypointPos - Vector3.left * size, globalWaypointPos + Vector3.left * size);
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 13b3fecfd3eaa684ca4b46e2f9b1377b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+235
View File
@@ -0,0 +1,235 @@
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Controller2D))]
public class Player : MonoBehaviour
{
public AudioClip JumpSound;
private AudioSource m_JumpAudioSource;
public float maxJumpHeight = 4;
public float minJumpHeight = 1;
public float timeToJumpApex = .4f;
float accelerationTimeAirborne = .2f;
float accelerationTimeGrounded = .1f;
float moveSpeed = 6;
public Vector2 wallJumpClimb;
public Vector2 wallJumpOff;
public Vector2 wallLeap;
public float wallSlideSpeedMax = 3;
public float wallStickTime = .25f;
float timeToWallUnstick;
float gravity;
float maxJumpVelocity;
float minJumpVelocity;
Vector3 velocity;
float velocityXSmoothing;
float jumpTimes = 0;
float jumpTimesOnWall = 0;
public float maxJumpTimes = 2;
public float maxJumpTimesOnWall = 1;
public bool IsDied = false;
public bool IsDiedOver = false;
Controller2D controller;
//Changed-bool-----------------------------------------------------------------------------------------------------------------------------------
public Animator animator;
bool boolLeft = false;
bool boolRight = false;
//Changed-bool-----------------------------------------------------------------------------------------------------------------------------------
void Start()
{
m_JumpAudioSource = GetComponent<AudioSource>();
controller = GetComponent<Controller2D>();
gravity = -(2 * maxJumpHeight) / Mathf.Pow(timeToJumpApex, 2);
maxJumpVelocity = Mathf.Abs(gravity) * timeToJumpApex;
minJumpVelocity = Mathf.Sqrt(2 * Mathf.Abs(gravity) * minJumpHeight);
print("Gravity: " + gravity + " Jump Velocity: " + maxJumpVelocity);
}
public void ImDied()
{
IsDied = true;
}
public void ImDiedOver()
{
IsDiedOver = true;
animator.SetBool("IsDiedOver", IsDiedOver);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
IsDied = false;
IsDiedOver = false;
}
animator.SetBool("IsDied", IsDied);
//When The Fox Is Alive`````````````````````````````
if (IsDied == false)
{
//Changed-bool-----------------------------------------------------------------------------------------------------------------------------------
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
boolLeft = true;
boolRight = false;
}
else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
boolRight = true;
boolLeft = false;
}
else if ((Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.A)) || (Input.GetKey(KeyCode.LeftArrow) && Input.GetKey(KeyCode.RightArrow)))
{
boolLeft = false;
boolRight = false;
}
else
{
boolLeft = false;
boolRight = false;
}
animator.SetFloat("Speed", velocity.x);
animator.SetBool("L", boolLeft);
animator.SetBool("R", boolRight);
if (Input.GetKey(KeyCode.Space))
{
animator.SetBool("IsJumping", true);
}
if (controller.collisions.below)
{
animator.SetBool("IsJumping", false);
}
if (controller.collisions.left && !controller.collisions.below && velocity.y < 0)
{
animator.SetBool("WallL", true);
}
else
{
animator.SetBool("WallL", false);
}
if (controller.collisions.right && !controller.collisions.below && velocity.y < 0)
{
animator.SetBool("WallR", true);
}
else
{
animator.SetBool("WallR", false);
}
//Changed-bool-----------------------------------------------------------------------------------------------------------------------------------
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
int wallDirX = (controller.collisions.left) ? -1 : 1;
float targetVelocityX = input.x * moveSpeed;
velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne);
bool wallSliding = false;
/*if ((controller.collisions.left || controller.collisions.right) && !controller.collisions.below && velocity.y < 0)
{
wallSliding = true;
if (velocity.y < -wallSlideSpeedMax)
{
velocity.y = -wallSlideSpeedMax;
}
if (timeToWallUnstick > 0)
{
velocityXSmoothing = 0;
velocity.x = 0;
if (input.x != wallDirX && input.x != 0)
{
timeToWallUnstick -= Time.deltaTime;
}
else
{
timeToWallUnstick = wallStickTime;
}
}
else
{
timeToWallUnstick = wallStickTime;
}
}*/
if (Input.GetKeyDown(KeyCode.Space))
{
if (wallSliding)
{
if (wallDirX == input.x && jumpTimesOnWall < maxJumpTimesOnWall)
{
velocity.x = -wallDirX * wallJumpClimb.x;
velocity.y = wallJumpClimb.y;
jumpTimesOnWall++;
}
else if (input.x == 0)
{
velocity.x = -wallDirX * wallJumpOff.x;
velocity.y = wallJumpOff.y;
}
/*else
{
velocity.x = -wallDirX * wallLeap.x;
velocity.y = wallLeap.y;
}*/
}
if (jumpTimes < maxJumpTimes)
{
m_JumpAudioSource.clip = JumpSound;
m_JumpAudioSource.Play();
velocity.y = maxJumpVelocity;
jumpTimes++;
}
}
if (Input.GetKeyUp(KeyCode.Space))
{
if (velocity.y > minJumpVelocity)
{
velocity.y = minJumpVelocity;
}
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime, input);
if (controller.collisions.above)
{
velocity.y = 0;
}
else if (controller.collisions.below)
{
jumpTimes = 0;
jumpTimesOnWall = 0; //限制爬墙跳次数有BUG
velocity.y = 0;
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4fc5821c8dc3d9c4c967510cb0d2590e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+61
View File
@@ -0,0 +1,61 @@
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(BoxCollider2D))]
public class RaycastController : MonoBehaviour
{
public LayerMask collisionMask;
public const float skinWidth = .015f;
public int horizontalRayCount = 4;
public int verticalRayCount = 4;
[HideInInspector]
public float horizontalRaySpacing;
[HideInInspector]
public float verticalRaySpacing;
[HideInInspector]
public BoxCollider2D thisCollider;
public RaycastOrigins raycastOrigins;
public virtual void Awake()
{
thisCollider = GetComponent<BoxCollider2D>();
}
public virtual void Start()
{
CalculateRaySpacing();
}
public void UpdateRaycastOrigins()
{
Bounds bounds = thisCollider.bounds;
bounds.Expand(skinWidth * -2);
raycastOrigins.bottomLeft = new Vector2(bounds.min.x, bounds.min.y);
raycastOrigins.bottomRight = new Vector2(bounds.max.x, bounds.min.y);
raycastOrigins.topLeft = new Vector2(bounds.min.x, bounds.max.y);
raycastOrigins.topRight = new Vector2(bounds.max.x, bounds.max.y);
}
public void CalculateRaySpacing()
{
Bounds bounds = thisCollider.bounds;
bounds.Expand(skinWidth * -2);
horizontalRayCount = Mathf.Clamp(horizontalRayCount, 2, int.MaxValue);
verticalRayCount = Mathf.Clamp(verticalRayCount, 2, int.MaxValue);
horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1);
verticalRaySpacing = bounds.size.x / (verticalRayCount - 1);
}
public struct RaycastOrigins
{
public Vector2 topLeft, topRight;
public Vector2 bottomLeft, bottomRight;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 93acc2b1f72c31e43b92470b0ed2a12c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+37
View File
@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SaveAnimation : MonoBehaviour {
public Animator animator;
bool IsSaved = false;
bool IsSavedOver = false;
// Use this for initialization
void Start () {
}
public void DoIsSaved()
{
IsSaved = true;
}
public void DoIsSavedOver()
{
IsSavedOver = true;
IsSaved = false;
}
public void UndoIsSavedOver()
{
IsSavedOver = false;
}
// Update is called once per frame
void Update () {
animator.SetBool("IsSaved", IsSaved);
animator.SetBool("IsSavedOver", IsSavedOver);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4489089a6d2ca4d4791c6fa73d7aa835
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+167
View File
@@ -0,0 +1,167 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
public class SaveandDie : MonoBehaviour {
public AudioClip DiedSound;
private AudioSource m_DiedAudioSource;
public UnityEvent DiedEvent;
public static float saveX = -46f;
public static float saveY = 19.32f;
public int counter0 = 0;
public int counter1 = 0;
public int counter2 = 0;
public int counter3 = 0;
public int counter4 = 0;
static int level = 0;
static float ResPown1X = -31f;
static float ResPown1Y = 19.31f;
static float ResPown2X = 27.72f;
static float ResPown2Y = 7.49f;
static float ResPown3X = -40f;
static float ResPown3Y = -3.5f;
// Use this for initialization
private void Awake()
{
if (DiedEvent == null)
DiedEvent = new UnityEvent();
}
void Start () {
Trans();
m_DiedAudioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))//Reset&GoBackToCheckPoint
{
ResetLevel(level);
Trans();
}
Vector3 tmp = GameObject.Find("Player").transform.position;
}
void OnTriggerEnter2D(Collider2D c)//Hit by some Toge
{
m_DiedAudioSource.clip = DiedSound;
m_DiedAudioSource.Play();
Debug.Log("AHHHHHH!");
DiedEvent.Invoke();
}
void SceneUnload()
{
if (counter0 >= 1)
{
SceneManager.UnloadSceneAsync(0);
counter0 = 0;
}
if (counter1 >= 1)
{
SceneManager.UnloadSceneAsync(1);
counter1 = 0;
}
if (counter2 >= 1)
{
SceneManager.UnloadSceneAsync(2);
counter2 = 0;
}
if (counter3 >= 1)
{
SceneManager.UnloadSceneAsync(3);
counter3 = 0;
}
if (counter4 >= 1)
{
SceneManager.UnloadSceneAsync(4);
counter4 = 0;
}
}
private void ResetLevel(int level)
{
switch (level)
{
case 0:
SceneUnload();
SceneManager.LoadScene(1);
counter1 = 1;
break;
case 1:
SceneUnload();
SceneManager.LoadScene(2);
counter2 = 1;
break;
case 2:
SceneUnload();
SceneManager.LoadScene(3);
counter4 = 1;
break;
case 3:
SceneUnload();
SceneManager.LoadScene(4);
counter4=1;
break;
}
}
void Trans()//Back to save point
{
GameObject.Find("Player").transform.position = new Vector3(saveX, saveY, 0);
}
//public-----------------------------
public void LevelHome()
{
level = 0;
saveX = -46f;
saveY = 19.32f;
ResetLevel(level);
}
public void DoSave()
{
Vector3 me = GameObject.Find("Player").transform.position;
saveX = me.x;
saveY = me.y;
}
public void TransToLevel1()
{
level = 1;
saveX = ResPown1X;
saveY = ResPown1Y;
ResetLevel(level);
}
public void TransToLevel2()
{
level = 2;
saveX = ResPown2X;
saveY = ResPown2Y;
ResetLevel(level);
}
public void TransToLevel3()
{
level = 3;
saveX = ResPown3X;
saveY = ResPown3Y;
ResetLevel(level);
}
//public-----------------------------
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5e3ed8b9fe81bc648b3e28dd025520b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+25
View File
@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundControler : MonoBehaviour {
public AudioClip Sound;
private AudioSource m_AudioSource;
// Use this for initialization
void Start () {
m_AudioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
m_AudioSource.clip = Sound;
}
public void Play()
{
m_AudioSource.Play();
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c9e31cbd74ddd94697531efaa3ca014
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+123
View File
@@ -0,0 +1,123 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TogeMove : RaycastController
{
public LayerMask passengerMask;
public Vector3[] localWaypoints;
Vector3[] globalWaypoints;
public float speed;
public bool cyclic;
public float waitTime=10000000000;
[Range(0, 2)]
public float easeAmount;
int fromWaypointIndex;
float percentBetweenWaypoints;
float nextMoveTime;
public bool MoveBool = false;
Dictionary<Transform, Controller2D> passengerDictionary = new Dictionary<Transform, Controller2D>();
public override void Start()
{
base.Start();
globalWaypoints = new Vector3[localWaypoints.Length];
for (int i = 0; i < localWaypoints.Length; i++)
{
globalWaypoints[i] = localWaypoints[i] + transform.position;
}
}
public void DoMove()
{
MoveBool = true;
}
public void DoNotMove()
{
MoveBool = false;
}
void Update()
{
if (MoveBool == true)
{
UpdateRaycastOrigins();
Vector3 velocity = CalculatePlatformMovement();
transform.Translate(velocity);
}
}
float Ease(float x)
{
float a = easeAmount + 1;
return Mathf.Pow(x, a) / (Mathf.Pow(x, a) + Mathf.Pow(1 - x, a));
}
Vector3 CalculatePlatformMovement()
{
if (Time.time < nextMoveTime)
{
return Vector3.zero;
}
fromWaypointIndex %= globalWaypoints.Length;
int toWaypointIndex = (fromWaypointIndex + 1) % globalWaypoints.Length;
float distanceBetweenWaypoints = Vector3.Distance(globalWaypoints[fromWaypointIndex], globalWaypoints[toWaypointIndex]);
percentBetweenWaypoints += Time.deltaTime * speed / distanceBetweenWaypoints;
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
float easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
Vector3 newPos = Vector3.Lerp(globalWaypoints[fromWaypointIndex], globalWaypoints[toWaypointIndex], easedPercentBetweenWaypoints);
if (percentBetweenWaypoints >= 1)
{
percentBetweenWaypoints = 0;
fromWaypointIndex++;
if (!cyclic)
{
if (fromWaypointIndex >= globalWaypoints.Length - 1)
{
fromWaypointIndex = 0;
System.Array.Reverse(globalWaypoints);
}
}
nextMoveTime = Time.time + waitTime;
}
return newPos - transform.position;
}
void OnDrawGizmos()
{
if (localWaypoints != null)
{
Gizmos.color = Color.red;
float size = .3f;
for (int i = 0; i < localWaypoints.Length; i++)
{
Vector3 globalWaypointPos = (Application.isPlaying) ? globalWaypoints[i] : localWaypoints[i] + transform.position;
Gizmos.DrawLine(globalWaypointPos - Vector3.up * size, globalWaypointPos + Vector3.up * size);
Gizmos.DrawLine(globalWaypointPos - Vector3.left * size, globalWaypointPos + Vector3.left * size);
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ff6a7bb1194cb8c4c88e090bfc4b6fa0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+124
View File
@@ -0,0 +1,124 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TogeMoveLevel2 : RaycastController
{
public LayerMask passengerMask;
public Vector3[] localWaypoints;
Vector3[] globalWaypoints;
public float speed;
public bool cyclic;
public float waitTime;
[Range(0, 2)]
public float easeAmount;
int fromWaypointIndex;
float percentBetweenWaypoints;
float nextMoveTime;
bool MoveBool = false;
Dictionary<Transform, Controller2D> passengerDictionary = new Dictionary<Transform, Controller2D>();
public override void Start()
{
base.Start();
globalWaypoints = new Vector3[localWaypoints.Length];
for (int i = 0; i < localWaypoints.Length; i++)
{
globalWaypoints[i] = localWaypoints[i] + transform.position;
}
}
public void DoMoveLevel2()
{
MoveBool = true;
}
public void DoNotMoveLevel2()
{
MoveBool = false;
}
void Update()
{
if (MoveBool == true)
{
UpdateRaycastOrigins();
Vector3 velocity = CalculatePlatformMovement();
transform.Translate(velocity);
}
}
float Ease(float x)
{
float a = easeAmount + 1;
return Mathf.Pow(x, a) / (Mathf.Pow(x, a) + Mathf.Pow(1 - x, a));
}
Vector3 CalculatePlatformMovement()
{
if (Time.time < nextMoveTime)
{
return Vector3.zero;
}
fromWaypointIndex %= globalWaypoints.Length;
int toWaypointIndex = (fromWaypointIndex + 1) % globalWaypoints.Length;
float distanceBetweenWaypoints = Vector3.Distance(globalWaypoints[fromWaypointIndex], globalWaypoints[toWaypointIndex]);
percentBetweenWaypoints += Time.deltaTime * speed / distanceBetweenWaypoints;
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
float easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
Vector3 newPos = Vector3.Lerp(globalWaypoints[fromWaypointIndex], globalWaypoints[toWaypointIndex], easedPercentBetweenWaypoints);
if (percentBetweenWaypoints >= 1)
{
percentBetweenWaypoints = 0;
fromWaypointIndex++;
if (!cyclic)
{
if (fromWaypointIndex >= globalWaypoints.Length - 1)
{
fromWaypointIndex = 0;
System.Array.Reverse(globalWaypoints);
}
}
nextMoveTime = Time.time + waitTime;
}
return newPos - transform.position;
}
void OnDrawGizmos()
{
if (localWaypoints != null)
{
Gizmos.color = Color.red;
float size = .3f;
for (int i = 0; i < localWaypoints.Length; i++)
{
Vector3 globalWaypointPos = (Application.isPlaying) ? globalWaypoints[i] : localWaypoints[i] + transform.position;
Gizmos.DrawLine(globalWaypointPos - Vector3.up * size, globalWaypointPos + Vector3.up * size);
Gizmos.DrawLine(globalWaypointPos - Vector3.left * size, globalWaypointPos + Vector3.left * size);
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 21e55de7c8b4ff04c8f02f2c3a6a16c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+28
View File
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrigerAnimation : MonoBehaviour {
public Animator animator;
bool On = false;
// Use this for initialization
void Start()
{
}
public void DoOn()
{
On = true;
}
// Update is called once per frame
void Update()
{
animator.SetBool("On", On);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d5bb19d8504ce049a7b863af3b09ac6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: