Answer the question
In order to leave comments, you need to log in
How to fix an error in object transform?
There is such an enemy code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Enemy : MonoBehaviour
{
public int health = 10;
Animator anim;
public Transform target;
public float speed = 3f;
public float attackRange = 1f;
public void TakeDamage(int damage)
{
health -= damage;
if(health <= 0)
{
anim.SetInteger("Death", 2);
anim.SetInteger("DeathEnemy", 2);
Die();
}
}
void Die()
{
Destroy(gameObject, 1f);
}
void Start()
{
anim = GetComponent<Animator>();
}
void Update()
{
transform.LookAt(target);
if(Vector3.Distance (transform.position, target.position) > attackRange)
{
transform.position += transform.forward * speed * Time.deltaTime;
if (Input.GetAxis("Horizontal") < 0)
{
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
if (Input.GetAxis("Horizontal") > 0)
{
transform.localRotation = Quaternion.Euler(0, 0, 0);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question