2d
Unity Notlar #1 - Kamera, Karakter ve Can Kodları
Kamera Karakter Takip Kodu:
public Transform target;
public Vector3 offset;
public float damping;
private void FixedUpdate()
{transform.position = Vector3.Lerp(transform.position , target.position, damping)+ offset;
}
public Transform target;
public Vector3 offset;
public float damping;
private void FixedUpdate()
{transform.position = Vector3.Lerp(transform.position , target.position, damping)+ offset;
}
Karakter Hareket ve Zıplama
public int speed, jumpSpeed;
bool faceRight;
Rigidbody2D rb;
Animator animator;
private void Start()
{
animator = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
float moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (Input.GetKeyDown(KeyCode.Space))
{ jump();
}
if (faceRight == false && moveInput <0)
{ flip();
}
else if (faceRight == true && moveInput > 0)
{
flip();
}
}
void jump()
{
rb.AddForce(Vector2.up * jumpSpeed);
}
void flip()
{
faceRight =! faceRight;
Vector3 scaler = transform.localScale;
scaler.x *= -1;
transform.localScale = scaler;
}
Can Scripti
public Image[] hearts;
public static int health = 3;
public int maxHealth = 3;
public Text messageText;
public string message;
public float mesajSuresi;
void Awake()
{
messageText.gameObject.SetActive(false);
messageText.text = message;
}
public void Damage(int amount)
{
hearts[health - 1].enabled = false;
health -= amount;
}
public void Regen(int amount)
{
if (health <3)
{
health += amount;
hearts[health - 1].enabled = true;
}
//for (int i = 0; i < maxHealth; i++)
//{
// hearts[i].enabled = true;
//}
}
private void Update()
{
if (health >= maxHealth)
{
health = maxHealth;
}
if (Input.GetKeyDown(KeyCode.H))
{
if (health > 0)
{
Damage(1);
}
}
if (Input.GetKey(KeyCode.F))
{
if (health < maxHealth)
{
Regen(1);
}
}
}
//kalp Toplayınca
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("heartTag"))
{
messageText.gameObject.SetActive(true);
Destroy(other.gameObject);
StartCoroutine(MesajGoster());
Regen(1);
}
}
IEnumerator MesajGoster()
{
yield return new WaitForSeconds(mesajSuresi);
messageText.gameObject.SetActive(false);
}
Yorum Gönder
2 Yorumlar
panel1.DOAnchorPos(new Vector 2(500,0), 0,5f).SetEase(Ease.InBack);
YanıtlaSilpanel2.DOAnchorPos(new Vector 2.zero, 0,5f)
Panel1 i sahneden animasyonu çıkar panel 2 yerine gelsin
//Alphasını artırarak başlat
YanıtlaSil--Buton tanımlanıp sürüklendi ve buton compomentine CANVAS GROUP eklendi. Kodlar ise;
buton1.Getcompoment().DOFade(1, 0.8f)
buton1.Getcompoment().DOFade(1, 0.8f).SetDelay(0.5f); --Setdelay Gecikmeli başlatır