Stanima minus - Форум - Все для Unity3d

Все для Unity3d> Stanima minus - Форум>
Страница 1 из 11
Форум » Unity » Assets » Stanima minus (Пытаюсь настроить бег персонажа и выносливость .)
Stanima minus
BlackRodgerДата: Пятница, 16.10.2015, 21:34 | Сообщение # 1
Новый писатель
Группа: Пользователи
Сообщений: 1
Статус: Offline
PlayerVitals 
using UnityEngine;
using System.Collections;

public class PlayerVitals : MonoBehaviour {
public GameObject guiVitals;
public GameObject guiStanima;
public static int curStanima;
public int maxStanima;
public int curHealth = 100;
public int maxHealth = 100;
public int recoveryAmount = 1;
public float recoverySpeed = 3;
public Color bloodColor = new Color(1.0f, 0.0f, 0.0f, 1.0f);
public Texture2D bloodyScreen;
public float fallDamageHeight = 8;
public AudioClip fallDamage;


[HideInInspector]public float percent;

private float alpha;
private float iv2;
private float minimumHealth = 40;
private float bmhRatio;
private PlayerMovement pm;
private CharacterController controller;

void Start() {

minimumHealth = 40;
pm = GetComponent<PlayerMovement>();
if(recoveryAmount != 0) {
StartCoroutine(Regenerate(0));
}
controller = GetComponent<CharacterController>();
}

void OnControllerColliderHit(ControllerColliderHit hit) {
Rigidbody rigid = hit.collider.attachedRigidbody;

if(rigid == null || rigid.isKinematic || hit.moveDirection.y < -0.3f) {
return;
}

Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);
rigid.velocity = pushDir * controller.velocity.magnitude * pm.pushPower / rigid.mass;
}

void OnGUI() {
GUI.color = new Color(bloodColor.r, bloodColor.g, bloodColor.b, alpha);
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), bloodyScreen);
}

void FixedUpdate() {
alpha = Mathf.Lerp(alpha, 0.9f - (percent * 0.9f), Time.deltaTime * 7);
curHealth = Mathf.Clamp(curHealth, 0, maxHealth);
percent = (float)curHealth / (float)maxHealth;
iv2 = pm.impactVelocity;
if(curHealth <= 0) {
Die();
}
Repud.GetChild(guiVitals, "health_text").GetComponent<TextMesh>().text = curHealth.ToString() + "/" + maxHealth.ToString();
Repud.GetChild(guiVitals, "health_bar").SendMessage("UpdateSize", percent);
Repud.GetChild(guiVitals, "stanima_text").GetComponent<TextMesh>().text = curHealth.ToString() + "/" + maxHealth.ToString();
Repud.GetChild(guiVitals, "stanima_bar").SendMessage("UpdateSize", percent);

bmhRatio = maxHealth / minimumHealth;

if(pm.grounded && pm.floating && iv2 > 1) {
SendMessage("FallAnimation", iv2);
}

if(pm.grounded && pm.floating && iv2 > fallDamageHeight) {
FallDamage(((iv2 - (fallDamageHeight * 0.8f)) * ((iv2 - (fallDamageHeight * 0.8f)) * 0.5f)));
iv2 = 0;
pm.floating = false;
}
}

public IEnumerator Regenerate(int amount) {
curHealth += amount;
yield return new WaitForSeconds(recoverySpeed);
StartCoroutine(Regenerate(recoveryAmount));
}

private void FallDamage(float prc) {
if((int)(prc) <= 0) {return;}
ApplyDamage((int)prc);
GetComponent<AudioSource>().clip = fallDamage;
GetComponent<AudioSource>().volume = 0.02f;
GetComponent<AudioSource>().Play();
}

public void ApplyDamage(float amount) {
curHealth -= (int)amount;
}

public void Die() {
Destroy(gameObject);
}
}
 
  

PlayerMovement

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(CharacterController))]
public class PlayerMovement : MonoBehaviour {
public bool canControl = true;


public float runSpeed = 5.0f;
public float sprintSpeed = 8.0f;
public float minus_stamina;
public int stamina_del;

public AnimationCurve slopeSpeedMultiplier = new AnimationCurve(new Keyframe(-90, 1.5f), new Keyframe(0, 1), new Keyframe(90, 0));

public float crouchSpeedModifier = 0.55f;
public float normalHeight = 1.75f;
public float crouchHeight = 1.0f;

public float gravity = 9.81f;
public float maxFallSpeed = 100.0f;

public float jumpHeight = 2.0f;

public LayerMask crouchDetect;
public float pushPower = 1.6f;

public bool  can_run = true;


[HideInInspector]public CollisionFlags collisionFlags; 
[HideInInspector]public bool grounded; 
[HideInInspector]public bool sprinting;
[HideInInspector]public bool crouching;
[HideInInspector]public bool inAir;
[HideInInspector]public bool floating;
[HideInInspector]public float impactVelocity;
[HideInInspector]public CharacterController controller;

private bool dontStand = false;
private RaycastHit ds;
private float moveSpeedAim;
private float curSpeed;
private Vector3 moveDirection;
private PlayerVitals pm;

void Start() {
pm = GetComponent<PlayerVitals>();
controller = GetComponent<CharacterController>();
moveSpeedAim = 1;
}

void LateUpdate() {
if(!grounded) {
impactVelocity = -controller.velocity.y;
floating = true;
}
}

void Can_run_bool ( bool cab  ){
can_run = cab;
}

void Update() {

grounded = controller.isGrounded;
if(grounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeedAim, -1, Input.GetAxis("Vertical") * moveSpeedAim);

if(moveDirection != Vector3.zero) {
float directionLength = moveDirection.magnitude;
moveDirection /= directionLength;
directionLength = Mathf.Min(1, directionLength);
directionLength  = Mathf.Pow(directionLength, 2);
moveDirection *= directionLength;
}

moveDirection = transform.TransformDirection(moveDirection);

if(Input.GetButton("Run") && Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") > 0 && !crouching && controller.velocity.magnitude > 0.5f) {
moveDirection *= sprintSpeed;
sprinting = true;
}
else if(crouching && !sprinting) {
moveDirection *= runSpeed * crouchSpeedModifier;
}
else if(can_run)  { 
sprinting = true;
}
else if(PlayerVitals.curStanima==0){ 
sprinting = false;
}
else {
moveDirection *= runSpeed;
sprinting = false;
}


if(Input.GetButton("Jump")) {
moveDirection.y = jumpHeight;
}

if(Physics.Raycast(transform.position, transform.up, out ds, (controller.height * 0.5f) + 0.1f, crouchDetect.value)) {
dontStand = true;
}
else {
dontStand = false;
}

if(!sprinting) {
if(Input.GetButton("Crouch")) {
controller.height = Mathf.Lerp(controller.height, crouchHeight, Time.deltaTime * 6);
controller.center = new Vector3(0, Mathf.Lerp(controller.center.y, -((normalHeight - crouchHeight) / 2), Time.deltaTime * 6), 0);
GameObject.Find("Head").SendMessage("CrouchMoveY", -(normalHeight - crouchHeight));
crouching = true;
{
gameObject.SendMessage("StaminaMinus",minus_stamina);

}
{ gameObject.SendMessage("StaminaMinus",-minus_stamina/stamina_del);
}
{
gameObject.SendMessage("StaminaMinus",-minus_stamina/stamina_del);

}
}


if(!Input.GetButton("Crouch") && !dontStand){
controller.height = Mathf.Lerp(controller.height, normalHeight, Time.deltaTime * 6);
controller.center = new Vector3(0, Mathf.Lerp(controller.center.y, 0, Time.deltaTime * 6), 0);
GameObject.Find("Head").SendMessage("CrouchMoveY", 0.0f);
crouching = false;
}
}
}

else {
inAir = true;
}

if(moveDirection.y > -maxFallSpeed) {
moveDirection.y -= Time.deltaTime * gravity;
}

controller.Move(moveDirection * Time.deltaTime);
}


void OnControllerColliderHit (ControllerColliderHit hit) {
}

public void SlowWhenAim(float spd) {
moveSpeedAim = spd;
}
}

Я затрудняюсь в том чтоб если персонаж бежит то у него - stanima и когда stanima = 0 он не может бежать , я вконец заплутался помогите если можете.
 
Форум » Unity » Assets » Stanima minus (Пытаюсь настроить бег персонажа и выносливость .)
Страница 1 из 11
Поиск:
Свернуть
Развернуть
Необходима авторизация
0
ТОП-5 САЙТА
НОВЫЕ ИГРЫ
ГОРЯЧИЕ ТЕМЫ
СЛУЧАЙНЫЕ ФАЙЛЫ