และหวังว่า Video Game Series นี้ก็จะมีประโยชน์ต่อท่านเช่นกัน
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour
{
public Transform target; // The position that that camera will be following.
public float smoothing = 5f; // The speed with which the camera will be following.
Vector3 offset; // The initial offset from the target.
void Start()
{
// Calculate the initial offset.
offset = transform.position - target.position;
}
void FixedUpdate()
{
// Create a postion the camera is aiming for based on the offset from the target.
Vector3 targetCamPos = target.position + offset;
// Smoothly interpolate between the camera's current position and it's target position.
transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMovment : MonoBehaviour
{
public float moveSpeed = 5.0f;
private Vector3 moveDirection;
private Rigidbody rb;
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
#if !MOBILE_INPUT
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical"));
#else
moveDirection = new Vector3(CrossPlatformInputManager.GetAxis("Horizontal"), 0 , CrossPlatformInputManager.GetAxis("Vertical"));
#endif
Move();
}
void Move()
{
moveDirection = moveDirection.normalized * moveSpeed * Time.deltaTime;
rb.MovePosition(transform.position + moveDirection);
}
}
NO GAME NO DREAM !!!!