Compare commits
2 Commits
ef7b99d4cf
...
0fe59fd1e3
| Author | SHA1 | Date | |
|---|---|---|---|
| 0fe59fd1e3 | |||
| e5d18b4c30 |
@@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class CameraVehicle : MonoBehaviour
|
||||||
|
{
|
||||||
|
public float sensitivityX = 20F;
|
||||||
|
public float sensitivityY = 20F;
|
||||||
|
|
||||||
|
public float minimumX = -360F;
|
||||||
|
public float maximumX = 360F;
|
||||||
|
|
||||||
|
public float minimumY = -90F;
|
||||||
|
public float maximumY = 90F;
|
||||||
|
|
||||||
|
public float moveSpeed = 0.25f;
|
||||||
|
|
||||||
|
float rotationX = 0F;
|
||||||
|
float rotationY = 0F;
|
||||||
|
|
||||||
|
Quaternion originalRotation;
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if(Input.GetKeyDown(KeyCode.LeftAlt) && Screen.lockCursor == false)
|
||||||
|
{
|
||||||
|
Screen.showCursor = false;
|
||||||
|
Screen.lockCursor = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(Input.GetKeyDown(KeyCode.Escape))
|
||||||
|
{
|
||||||
|
Screen.lockCursor = false;
|
||||||
|
Screen.showCursor = true;
|
||||||
|
}
|
||||||
|
if(Screen.lockCursor == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
|
||||||
|
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||||
|
|
||||||
|
rotationX = ClampAngle(rotationX, minimumX, maximumX);
|
||||||
|
rotationY = ClampAngle(rotationY, minimumY, maximumY);
|
||||||
|
|
||||||
|
Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
|
||||||
|
Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);
|
||||||
|
|
||||||
|
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
|
||||||
|
|
||||||
|
Vector3 pos = transform.position;
|
||||||
|
Vector3 direction = Vector3.zero;
|
||||||
|
if(Input.GetKey(KeyCode.W))
|
||||||
|
{
|
||||||
|
direction += Vector3.forward;
|
||||||
|
}
|
||||||
|
if(Input.GetKey(KeyCode.S))
|
||||||
|
{
|
||||||
|
direction -= Vector3.forward;
|
||||||
|
}
|
||||||
|
if(Input.GetKey(KeyCode.D))
|
||||||
|
{
|
||||||
|
direction += Vector3.right;
|
||||||
|
}
|
||||||
|
if(Input.GetKey(KeyCode.A))
|
||||||
|
{
|
||||||
|
direction += Vector3.left;
|
||||||
|
}
|
||||||
|
if(Input.GetKey(KeyCode.Space))
|
||||||
|
{
|
||||||
|
direction += Vector3.up;
|
||||||
|
}
|
||||||
|
if(Input.GetKey(KeyCode.LeftShift))
|
||||||
|
{
|
||||||
|
direction += Vector3.down;
|
||||||
|
}
|
||||||
|
if(Input.GetKey(KeyCode.LeftControl))
|
||||||
|
{
|
||||||
|
direction *= 2;
|
||||||
|
}
|
||||||
|
pos += transform.rotation * direction * moveSpeed;
|
||||||
|
transform.position = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
originalRotation = transform.localRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ClampAngle(float angle, float min, float max)
|
||||||
|
{
|
||||||
|
if (angle < -360F)
|
||||||
|
angle += 360F;
|
||||||
|
if (angle > 360F)
|
||||||
|
angle -= 360F;
|
||||||
|
return Mathf.Clamp(angle, min, max);
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
-4
@@ -5,17 +5,73 @@ using UnityEngine;
|
|||||||
public class Game : MonoBehaviour
|
public class Game : MonoBehaviour
|
||||||
{
|
{
|
||||||
Camera cam;
|
Camera cam;
|
||||||
|
GameObject world;
|
||||||
|
|
||||||
|
public void TextureObject(GameObject go)
|
||||||
|
{
|
||||||
|
MeshFilter mf = (MeshFilter)go.GetComponent(typeof(MeshFilter));
|
||||||
|
if (!mf) return;
|
||||||
|
Mesh mesh = mf.mesh;
|
||||||
|
Vector2[] uvs = new Vector2[mesh.vertices.Length];
|
||||||
|
int[] tris = mesh.triangles;
|
||||||
|
for (int i = 0; i < tris.Length; i += 3)
|
||||||
|
{
|
||||||
|
Vector3 a = go.transform.TransformPoint(mesh.vertices[tris[i]]);
|
||||||
|
Vector3 b = go.transform.TransformPoint(mesh.vertices[tris[i+1]]);
|
||||||
|
Vector3 c = go.transform.TransformPoint(mesh.vertices[tris[i+2]]);
|
||||||
|
Vector3 n = Vector3.Cross(a-c, b-c).normalized;
|
||||||
|
if (
|
||||||
|
Vector3.Dot(Vector3.up, n) >= 0.5f ||
|
||||||
|
(Vector3.Dot(-Vector3.up, n) >= 0.5f))
|
||||||
|
{
|
||||||
|
uvs[tris[i]] = new Vector2(a.x, a.z);
|
||||||
|
uvs[tris[i+1]] = new Vector2(b.x, b.z);
|
||||||
|
uvs[tris[i+2]] = new Vector2(c.x, c.z);
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
Vector3.Dot(Vector3.right, n) >= 0.5f ||
|
||||||
|
(Vector3.Dot(Vector3.left, n) >= 0.5f))
|
||||||
|
{
|
||||||
|
uvs[tris[i]] = new Vector2(a.y, a.z);
|
||||||
|
uvs[tris[i+1]] = new Vector2(b.y, b.z);
|
||||||
|
uvs[tris[i+2]] = new Vector2(c.y, c.z);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uvs[tris[i]] = new Vector2(a.y, a.x);
|
||||||
|
uvs[tris[i + 1]] = new Vector2(b.y, b.x);
|
||||||
|
uvs[tris[i + 2]] = new Vector2(c.y, c.x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mesh.uv = uvs;
|
||||||
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
cam = Camera.main;
|
cam = Camera.main;
|
||||||
cam.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
|
cam.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
|
||||||
|
cam.transform.position = new Vector3(0f, 0f, 0f);
|
||||||
|
|
||||||
|
world = new GameObject("World");
|
||||||
|
|
||||||
|
GameObject cube = (GameObject)Resources.Load("cube");
|
||||||
|
cube = (GameObject)GameObject.Instantiate(cube);
|
||||||
|
cube.name = "cube";
|
||||||
|
cube.transform.parent = world.transform;
|
||||||
|
cube.transform.localPosition = new Vector3(0f, 0f, 0f);
|
||||||
|
cube.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
|
||||||
|
cube.transform.localScale = new Vector3(10f, 10f, 10f);
|
||||||
|
TextureObject(cube);
|
||||||
|
|
||||||
|
foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)))
|
||||||
|
{
|
||||||
|
go.SendMessage(
|
||||||
|
"OnSceneGenerated",
|
||||||
|
SendMessageOptions.DontRequireReceiver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixedUpdate()
|
public void Update()
|
||||||
{
|
{
|
||||||
Vector3 lea = cam.transform.localEulerAngles;
|
|
||||||
lea.y = (lea.y + 0.1f) % 360f;
|
|
||||||
cam.transform.localEulerAngles = lea;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,8 @@ public class Init : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public void Awake()
|
public void Awake()
|
||||||
{
|
{
|
||||||
|
Screen.fullScreen = false;
|
||||||
|
|
||||||
Application.LoadLevel(Application.loadedLevel + 1);
|
Application.LoadLevel(Application.loadedLevel + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user