Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class CharacterMNGR : MonoBehaviour, IBeginDragHandler, IDragHandler
{
public float jumpPower;
private Vector3 moveVector;
public float gravityForce;
private CharacterController ch_controller;
public void OnBeginDrag(PointerEventData eventData)
{
if ((Mathf.Abs(eventData.delta.x)) > (Mathf.Abs(eventData.delta.y)))
{
if (eventData.delta.x > 0)
{ }
else
{ }
}
else
{
if (eventData.delta.y > 0)
{
if (ch_controller.isGrounded) gravityForce = jumpPower;
}
else
{ }
}
}
public void OnDrag(PointerEventData eventData)
{
}
private void Start()
{
ch_controller = GetComponent<CharacterController>();
}
private void Update()
{
GamingGravity();
CharacterMove();
}
private void GamingGravity()
{
if (!ch_controller.isGrounded) gravityForce -= 20f * Time.deltaTime;
else gravityForce = -1f;
}
private void CharacterMove()
{
moveVector = Vector3.zero;
moveVector.y = gravityForce;
ch_controller.Move(moveVector * Time.deltaTime);
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class CharacterMNGR : MonoBehaviour, IBeginDragHandler, IDragHandler
{
public float jumpPower;
private Vector3 moveVector;
public float gravityForce;
private CharacterController ch_controller;
public void OnBeginDrag(PointerEventData eventData)
{
if ((Mathf.Abs(eventData.delta.x)) > (Mathf.Abs(eventData.delta.y)))
{
if (eventData.delta.x > 0)
{ }
else
{ }
}
else
{
if (eventData.delta.y > 0)
{
if (ch_controller.isGrounded) gravityForce = jumpPower;
}
else
{ }
}
}
public void OnDrag(PointerEventData eventData)
{
}
private void Start()
{
ch_controller = GetComponent<CharacterController>();
}
private void Update()
{
GamingGravity();
CharacterMove();
}
private void GamingGravity()
{
if (!ch_controller.isGrounded) gravityForce -= 20f * Time.deltaTime;
else gravityForce = -1f;
}
private void CharacterMove()
{
moveVector = Vector3.zero;
moveVector.y = gravityForce;
ch_controller.Move(moveVector * Time.deltaTime);
}
}