1
0
Fork 0

Added Camera Movement

This commit is contained in:
ALoTron 2018-04-21 20:19:06 +02:00
parent 5c3552d1a0
commit 15e6166e5b
3 changed files with 37 additions and 1 deletions

View 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;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5d9a051e822e2cf4ea3ca01c5a4df37c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -20,7 +20,7 @@ public class PlayerMovement : MonoBehaviour {
rigidbody2D = GetComponent<Rigidbody2D>();
}
void FixedUpdate() {
void Update() {
Vector3 speedVec = new Vector3(rigidbody2D.velocity.x, rigidbody2D.velocity.y, 0);
float speed = speedVec.magnitude;