Q1:物体删不掉
Destroy(toppoint);
Destroy(bottompoint);
一定要将他改成
Destroy(toppoint.gameobject);
Destory(bottompoint.gameobect);
不然不能删除在游戏中的物体
Q2:添加完animaton但是不能添加proverty
可以尝试吧animation也挂在object上
Q3:如何更加简洁的让敌人死亡的代码不冗余
去年夏天我是用的方法是在使用多个标签,进行碰撞,然后destroy
今天学到了建立一个大类。通过继承重写。并且学会在代码之中之间调用另一个脚本的代码。补充不足。
{
if (collision.gameObject.tag == "Enemies")
{
//可以调用enemt当中所有的代码函数组件
Enemy enemy = collision.gameObject.GetComponent<Enemy>();
if (animator.GetBool("falling"))
{
enemy.JumpOn();
//Destroy(collision.gameObject);
rigidbody.velocity = new Vector2(rigidbody.velocity.x, jumpfource * Time.deltaTime);
animator.SetBool("jumpping", true);
animator.SetBool("idle", false);
}
else if(transform.position.x<collision.gameObject.transform.position.x)
{
rigidbody.velocity = new Vector2(-5f, rigidbody.velocity.y);
isHurt = true;
}
else if (transform.position.x > collision.gameObject.transform.position.x)
{
rigidbody.velocity = new Vector2(-5f, rigidbody.velocity.y);
isHurt = true;
}
}
Q4:除了输入按键的代码来进行移动
{
float horizontalmove = Input.GetAxis("Horizontal");
float facedirection= Input.GetAxisRaw("Horizontal");
if (horizontalmove != 0)
{
rigidbody.velocity = new Vector2(horizontalmove * speed/**Time.deltaTime*/, rigidbody.velocity.y);
animator.SetFloat("running", Mathf.Abs(facedirection));
}
if (facedirection != 0)
{
rigidbody.transform.localScale = new Vector3(facedirection, 1, 1);
}
if (Input.GetButtonDown("Jump")&&collider.IsTouchingLayers(ground))
{
rigidbody.velocity = new Vector2(rigidbody.velocity.x, jumpfource /** Time.deltaTime*/);
animator.SetBool("jumpping", true);
animator.SetBool("idle", false);
}
}
```