유니티 c# RayCast 디버그 방법(눈으로 디버그라인을 그리는방법)

|

if (Input.GetButtonDown("Fire1"))

        {

            //클릭시 실행

            //print("fire1");

            //RayCast 충돌처리

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;

 

            if(Physics.Raycast(ray, out hit, Mathf.Infinity))

            {

                print("raycast hit!");

                Debug.DrawRay(ray.origin, ray.direction * 10f, Color.red, 5f);

            }

 

        }



ray.origin = 시작위치 

ray.direction * 10f = 방향

Color.red = 디버그 라인 색깔

 5f = 유지시간




Trackback 0 And Comment 0

c# 기본서 추천(c# IN DEPTH)

|



C# IN DEPTH

저자
존 스킷 지음
출판사
웰북 | 2009-09-07 출간
카테고리
컴퓨터/IT
책소개
『C# IN DEPTH』은 존 스킷이 저술한 것이다. C# 2와...
가격비교 글쓴이 평점  



이 책이 얼마나 좋은지에 대해서 더 떠들어봤자 입만 아플 것이고(아니, 손가락이 아프겠군요), 번역서에 서문으로 적은 내용을 일부 인용하는 것으로 이 책의 소개를 대신할까 합니다.

정말 좋은 책이라고 c# 을 하시는 분들은 많이 추천해 주시더라고요.

뭐 가장 큰 단점은 번역이라고 할정도로 책 내용은 좋다.

천천히 읽어봅시다.

자꾸 책만 사날리는게 아닌가 싶기도 하지만 c# 책은 한권도 사지 않아서 일단 질러놨습니다.


Trackback 0 And Comment 0

Animation Parameters

|

Animation Parameters

Animation Parameters are variables that are defined within the animation system but can also be accessed and assigned values from scripts. For example, the value of a parameter can be updated by an animation curve and then accessed from a script so that, say, the pitch of a sound effect can be varied as if it were a piece of animation. Likewise, a script can set parameter values to be picked up by Mecanim. For example, a script can set a parameter to control a Blend Tree.

Default parameter values can be set up using the Parameters widget in the bottom left corner of the Animator window. They can be of four basic types:

  • Vector - a point in space
  • Int - an integer (whole number)
  • Float - a number with a fractional part
  • Bool - true or false value

Parameters can be assigned values from a script using functions in the Animator class: SetFloatSetInt, and SetBool.

Here's an example of a script that modifies parameters based on user input

using UnityEngine;
using System.Collections;


public class AvatarCtrl : MonoBehaviour {

	protected Animator animator;

	public float DirectionDampTime = .25f;

	void Start () 
	{
		animator = GetComponent<Animator>();
	}

	void Update () 
	{
		if(animator)
		{
			//get the current state
			AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);

			//if we're in "Run" mode, respond to input for jump, and set the Jump parameter accordingly. 
			if(stateInfo.nameHash == Animator.StringToHash("Base Layer.RunBT"))
			{
				if(Input.GetButton("Fire1")) 
					animator.SetBool("Jump", true );
			}
			else
			{
				animator.SetBool("Jump", false);				
			}

			float h = Input.GetAxis("Horizontal");
			float v = Input.GetAxis("Vertical");

			//set event parameters based on user input
			animator.SetFloat("Speed", h*h+v*v);
			animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);
		}		
	}   		  
}


Trackback 0 And Comment 0