Ну особо и показать нечего в плане.. Весь код взят из той серии уроков.waruiyume писал(а):Какой подсказки вы ожидали, если нет кода, зато есть утверждение невозможного?
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerPlatformerController : PhysicsObject {
public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;
private SpriteRenderer layerBody;
private Animator animator;
private CapsuleCollider2D capsuleCollider;
public GameObject layers;
public bool sideMove; //false-спрайт направлен на право,true-на лево
public float velocityY;
// Use this for initialization
void Awake ()
{
layerBody = layers.transform.GetChild(1).GetComponent<SpriteRenderer> ();
animator = GetComponent<Animator> ();
capsuleCollider = GetComponent<CapsuleCollider2D>();
sideMove = false;
}
protected override void ComputeVelocity()
{
Vector2 move = Vector2.zero;
move.x = Input.GetAxis ("Horizontal");
velocityY = velocity.y;
if (Input.GetButtonDown ("Jump") && grounded) {
velocity.y = jumpTakeOffSpeed;
} else if (Input.GetButtonUp ("Jump"))
{
if (velocity.y > 0) {
velocity.y = velocity.y * 0.5f;
}
}
bool flipSprite = (layerBody.flipX ? (move.x > 0.01f) : (move.x < 0.01f));
if (flipSprite)
{
//layerBody.flipX = !layerBody.flipX;
//sideMove=!sideMove;
//layers.transform.GetChild(0).localPosition -= layers.transform.GetChild(0).localPosition*2;
}
if(sideMove){layerBody.flipX=true;}
else{layerBody.flipX=false;}
if(move.x > 0.01){sideMove=false;}
else if (move.x < -0.01){sideMove=true;}
//animator.SetBool ("grounded", grounded);
layerBody.GetComponent<Animator>().SetFloat ("Run", Mathf.Abs (move.x));
if(velocity.y>0){
layerBody.GetComponent<Animator>().SetBool("Jump",true);
}
else if(velocity.y<0){
layerBody.GetComponent<Animator>().SetBool("Jump",false);
}
Debug.DrawLine(transform.position,new Vector2(transform.position.x,velocity.y),Color.red);
//Debug.Log("velocity.y: "+velocity.y);
targetVelocity = move * maxSpeed;
}
}
using System.Collections.Generic;
using UnityEngine;
public class PlayerPlatformerController : PhysicsObject {
public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;
private SpriteRenderer layerBody;
private Animator animator;
private CapsuleCollider2D capsuleCollider;
public GameObject layers;
public bool sideMove; //false-спрайт направлен на право,true-на лево
public float velocityY;
// Use this for initialization
void Awake ()
{
layerBody = layers.transform.GetChild(1).GetComponent<SpriteRenderer> ();
animator = GetComponent<Animator> ();
capsuleCollider = GetComponent<CapsuleCollider2D>();
sideMove = false;
}
protected override void ComputeVelocity()
{
Vector2 move = Vector2.zero;
move.x = Input.GetAxis ("Horizontal");
velocityY = velocity.y;
if (Input.GetButtonDown ("Jump") && grounded) {
velocity.y = jumpTakeOffSpeed;
} else if (Input.GetButtonUp ("Jump"))
{
if (velocity.y > 0) {
velocity.y = velocity.y * 0.5f;
}
}
bool flipSprite = (layerBody.flipX ? (move.x > 0.01f) : (move.x < 0.01f));
if (flipSprite)
{
//layerBody.flipX = !layerBody.flipX;
//sideMove=!sideMove;
//layers.transform.GetChild(0).localPosition -= layers.transform.GetChild(0).localPosition*2;
}
if(sideMove){layerBody.flipX=true;}
else{layerBody.flipX=false;}
if(move.x > 0.01){sideMove=false;}
else if (move.x < -0.01){sideMove=true;}
//animator.SetBool ("grounded", grounded);
layerBody.GetComponent<Animator>().SetFloat ("Run", Mathf.Abs (move.x));
if(velocity.y>0){
layerBody.GetComponent<Animator>().SetBool("Jump",true);
}
else if(velocity.y<0){
layerBody.GetComponent<Animator>().SetBool("Jump",false);
}
Debug.DrawLine(transform.position,new Vector2(transform.position.x,velocity.y),Color.red);
//Debug.Log("velocity.y: "+velocity.y);
targetVelocity = move * maxSpeed;
}
}
Еще небольшой вопрос.. У персонажа скажем 100 хп и он может поднять до 500хп. До 400 все отображается одной шкалой, после перехода за этот порог (в 400хп), поверх первой шкалы начинает расти вторая. Но как это сделать адекватно?
Вычисление размера "шкалы" идет так
Синтаксис:
Используется csharp
var life_scale = (float)there/((float)max/100);
Пробовал сделать так:
Синтаксис:
Используется csharp
var life_scale = (float)life.there/((float)life.max/100);
var lifePro_scale = (float)(life.there-400)/((float)(life.max-400)/100);
if(life.there<=400){
scaleLife.transform.GetComponent<Image>().fillAmount = life_scale/100; //определяем "процент" растянутости шкалы
scaleLifePro.transform.GetComponent<Image>().fillAmount = 0;
}else{
scaleLife.transform.GetComponent<Image>().fillAmount = 1;
scaleLifePro.transform.GetComponent<Image>().fillAmount = lifePro_scale/100;
}
var lifePro_scale = (float)(life.there-400)/((float)(life.max-400)/100);
if(life.there<=400){
scaleLife.transform.GetComponent<Image>().fillAmount = life_scale/100; //определяем "процент" растянутости шкалы
scaleLifePro.transform.GetComponent<Image>().fillAmount = 0;
}else{
scaleLife.transform.GetComponent<Image>().fillAmount = 1;
scaleLifePro.transform.GetComponent<Image>().fillAmount = lifePro_scale/100;
}