Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class PlayerCcontrolol : MonoBehaviour {
public GameObject pplayer;
public int speed = 6;
public float xrotation;
public float yrotation;
public GameObject camera1;
public Rigidbody rb;
public float zirow;
public bool jump = true;
public Vector3 lf;
public Vector3 rht;
public Vector3 beh;
public Vector3 fw;
public Vector3 du;
void OnCollisionEnter(Collision Col) {
jump = true;
}
void Start() {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
lf = transform.TransformDirection(Vector3.left);
rht = transform.TransformDirection(Vector3.right);
beh = transform.TransformDirection(Vector3.back);
fw = transform.TransformDirection(Vector3.forward);
du = transform.TransformDirection(Vector3.down);
xrotation = camera1.GetComponent<CameraControll>().yRotation;
yrotation = camera1.GetComponent<CameraControll>().xRotation;
gameObject.transform.eulerAngles = new Vector3(0,xrotation,0);
pplayer.transform.eulerAngles = new Vector3(0/*yrotation*/,xrotation,0);
if (Input.GetKey(KeyCode.W)&&!Physics.Raycast(transform.position,fw,1F) )
{
gameObject.transform.position += gameObject.transform.forward * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.S)&&!Physics.Raycast(transform.position,beh,1F))
{
gameObject.transform.position -= gameObject.transform.forward * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.A)&&!Physics.Raycast(transform.position,lf,1F))
{
gameObject.transform.position -= gameObject.transform.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D)&&!Physics.Raycast(transform.position,rht,1F))
{
gameObject.transform.position += gameObject.transform.right * speed * Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.Space))
{
if (Physics.Raycast(transform.position,du,1.7F)){
rb.AddForce(0,8,0, ForceMode.Impulse);
jump = false;
}
}
}
}
using System.Collections;
public class PlayerCcontrolol : MonoBehaviour {
public GameObject pplayer;
public int speed = 6;
public float xrotation;
public float yrotation;
public GameObject camera1;
public Rigidbody rb;
public float zirow;
public bool jump = true;
public Vector3 lf;
public Vector3 rht;
public Vector3 beh;
public Vector3 fw;
public Vector3 du;
void OnCollisionEnter(Collision Col) {
jump = true;
}
void Start() {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
lf = transform.TransformDirection(Vector3.left);
rht = transform.TransformDirection(Vector3.right);
beh = transform.TransformDirection(Vector3.back);
fw = transform.TransformDirection(Vector3.forward);
du = transform.TransformDirection(Vector3.down);
xrotation = camera1.GetComponent<CameraControll>().yRotation;
yrotation = camera1.GetComponent<CameraControll>().xRotation;
gameObject.transform.eulerAngles = new Vector3(0,xrotation,0);
pplayer.transform.eulerAngles = new Vector3(0/*yrotation*/,xrotation,0);
if (Input.GetKey(KeyCode.W)&&!Physics.Raycast(transform.position,fw,1F) )
{
gameObject.transform.position += gameObject.transform.forward * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.S)&&!Physics.Raycast(transform.position,beh,1F))
{
gameObject.transform.position -= gameObject.transform.forward * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.A)&&!Physics.Raycast(transform.position,lf,1F))
{
gameObject.transform.position -= gameObject.transform.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D)&&!Physics.Raycast(transform.position,rht,1F))
{
gameObject.transform.position += gameObject.transform.right * speed * Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.Space))
{
if (Physics.Raycast(transform.position,du,1.7F)){
rb.AddForce(0,8,0, ForceMode.Impulse);
jump = false;
}
}
}
}
Помогите пожалуйста