Added Camera Movement
This commit is contained in:
parent
5c3552d1a0
commit
15e6166e5b
3 changed files with 37 additions and 1 deletions
25
Assets/Scripts/CameraControl.cs
Normal file
25
Assets/Scripts/CameraControl.cs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class CameraControl : MonoBehaviour {
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
public GameObject followThis;
|
||||||
|
|
||||||
|
private Vector3 offset;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
offset = transform.position - followThis.transform.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LateUpdate()
|
||||||
|
{
|
||||||
|
var target = followThis.transform.position + offset;
|
||||||
|
var targetVec = target - transform.position;
|
||||||
|
targetVec.Scale (new Vector3 (0.05f, 0.05f, 0));
|
||||||
|
|
||||||
|
transform.position = transform.position + targetVec;
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/CameraControl.cs.meta
Normal file
11
Assets/Scripts/CameraControl.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5d9a051e822e2cf4ea3ca01c5a4df37c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -20,7 +20,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||||
rigidbody2D = GetComponent<Rigidbody2D>();
|
rigidbody2D = GetComponent<Rigidbody2D>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate() {
|
void Update() {
|
||||||
Vector3 speedVec = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y, 0);
|
Vector3 speedVec = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y, 0);
|
||||||
float speed = speedVec.magnitude;
|
float speed = speedVec.magnitude;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue