Jump added
This commit is contained in:
@@ -527,6 +527,7 @@ GameObject:
|
||||
- component: {fileID: 963194228}
|
||||
- component: {fileID: 963194227}
|
||||
- component: {fileID: 963194226}
|
||||
- component: {fileID: 963194229}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
@@ -592,14 +593,27 @@ Transform:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_LocalRotation: {x: -0.34271878, y: 0.0005611182, z: -0.00020496178, w: -0.93943787}
|
||||
m_LocalPosition: {x: 4.894763, y: 8.347612, z: -8.222608}
|
||||
m_LocalRotation: {x: 0.38268337, y: -0.00054823596, z: 0.00022708677, w: 0.92387944}
|
||||
m_LocalPosition: {x: 8.406, y: 4.7, z: -1.148}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_LocalEulerAnglesHint: {x: 45, y: -0.068, z: 0}
|
||||
--- !u!114 &963194229
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: be9660cc0d9627849873ca175d296a63, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
player: {fileID: 1286409040}
|
||||
--- !u!1 &1145553048
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -747,11 +761,10 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: cb738793c052dd54597cff2d5ea33de3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
moveSpeed: 5
|
||||
direction: {x: 0, y: 0, z: 0}
|
||||
moveSpeed: 250
|
||||
jumpforce: 350
|
||||
rb: {fileID: 1286409046}
|
||||
horizontal: 0
|
||||
vertical: 0
|
||||
isJumping: 0
|
||||
--- !u!54 &1286409046
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
19
Assets/Scripts/CameraController.cs
Normal file
19
Assets/Scripts/CameraController.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
private Vector3 offset;
|
||||
|
||||
void Start()
|
||||
{
|
||||
offset = transform.position - player.transform.position;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
transform.position = player.transform.position + offset;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CameraController.cs.meta
Normal file
11
Assets/Scripts/CameraController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be9660cc0d9627849873ca175d296a63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,26 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Movement : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed = 5f;
|
||||
private Vector3 direction;
|
||||
public Rigidbody rb;
|
||||
private float horizontal, vertical;
|
||||
|
||||
private void Awake() {
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
horizontal = Input.GetAxis("Horizontal");
|
||||
vertical = Input.GetAxis("Vertical");
|
||||
|
||||
direction = new Vector3(horizontal, 0,vertical);
|
||||
|
||||
rb.AddForce(direction * moveSpeed);
|
||||
}
|
||||
}
|
||||
42
Assets/Scripts/PlayerController.cs
Normal file
42
Assets/Scripts/PlayerController.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed = 5f;
|
||||
public float jumpforce = 5f;
|
||||
private Vector3 direction;
|
||||
public Rigidbody rb;
|
||||
private float horizontal, vertical;
|
||||
public float isJumping;
|
||||
private bool isOnGround;
|
||||
|
||||
|
||||
private void Awake() {
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
horizontal = Input.GetAxis("Horizontal");
|
||||
vertical = Input.GetAxis("Vertical");
|
||||
isJumping = Input.GetAxis("Jump");
|
||||
|
||||
if (isJumping > 0 && isOnGround) {
|
||||
rb.AddForce(new Vector3(horizontal, jumpforce, vertical));
|
||||
isOnGround = false;
|
||||
}
|
||||
|
||||
direction = new Vector3(horizontal, 0,vertical);
|
||||
|
||||
rb.AddForce(direction * moveSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision) {
|
||||
if (collision.collider.CompareTag("Ground")) {
|
||||
isOnGround = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user