键盘小球控制代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Csharp : MonoBehaviour {
public float speed;
void Start () {
speed = 100;
}
// Update is called once per frame
void Update () {
}
void FixedUpdate(){
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
}
}
镜头避免旋转代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraController : MonoBehaviour {
public GameObject player;
public Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position;
}
// Update is called once per frame
void LateUpdate () {
transform.position = player.transform.position + offset;
}
}