统一2D C#编码问题 [英] unity 2D C# coding problem

查看:112
本文介绍了统一2D C#编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的2d角色再次出现问题...我修复了以前的问题,但新问题是,我不能让我的角色打...他走路,他跳得很好,但我是在打孔运动或类似的任何问题...我做了一个拳击动画,我做了一个转换到空闲和从动态窗口中的空闲到puch ...而且我做了一个触发参数但我的代码剂量工作...可能是我写的代码是完整的...如果那是错的请告诉我什么叫做id?谢谢



hi there i have a problem with my 2d character again...i fixed my previous problems but the new problem is that,that i cant make my character punchin...he walks,he jumps pretty well but i'm in some problem with punchin movement or anything like this...i made a punch animation and i made a transation to the idle and from idle to puch in the animator window...and also i made a trigger parameter but my code dosent work...may be the code i wrote is completley worng...if thats wrong please tell me what shout id do? thanks

using UnityEngine;
using System.Collections;

public class ScrorpionControllerScript : MonoBehaviour 
{
	public float maxSpeed = 10f;
	bool facingRight = true;

	Animator anim;

	bool grounded = false;
	public Transform groundCheck;
	float groundRadius = 0.2f;
	public LayerMask whatIsGround;
	float jumpTime, jumpDelay = 0.2f;
	bool jumped;
	float punchTime, punchDelay = .5f;
	bool punch;


	// Use this for initialization
	void Start () 
	{
		anim = GetComponent<Animator> ();
	}
	
	// Update is called once per frame
	void FixedUpdate () 
	{
		grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
		anim.SetBool ("Ground", grounded);

		anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);

		anim.SetBool ("Ground", grounded);

		float move = Input.GetAxis ("Horizontal");

		anim.SetFloat ("wa", Mathf.Abs (move));

			rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);

		    if(move > 0 &&! facingRight)
			Flip ();
		    else if (move < 0 && facingRight)
			Flip ();
	}

	void Update()
	{
		if(Input.GetKeyDown (KeyCode.Space) && grounded)
		{
			rigidbody2D.AddForce(transform.up * 275f);
			jumpTime = jumpDelay;
			anim.SetTrigger("Jump");
			jumped = true;
		}
		jumpTime -= Time.deltaTime;
		if (jumpTime <= 0 && grounded && jumped) 
		{
	    	anim.SetTrigger ("Land");
			jumped = false;
		}
		if (Input.GetKeyDown (KeyCode.R));
		{
			punchTime = punchDelay;
			anim.SetTrigger("punch");
			punch = true;
		}
	}

	void Flip()
	{
		facingRight = !facingRight;
		Vector3 theScale = transform.localScale;
		theScale.x *= -1;
		transform.localScale = theScale;
	}
}

推荐答案

这篇关于统一2D C#编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆