Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
using System.Collections;
public class MovePlayer : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
Transform target;
float rotateSpeed = 10;
// Use this for initialization
void Start () {
// 將 target指定名稱為Imege的物件,並取得物件的Transform
target = GameObject.Find("Image").GetComponent<Transform>();
}
void Update () {
@smallrice45
smallrice45 / NGUIButtonEvent
Created March 19, 2014 16:31
NGUI 按鈕觸發
using UnityEngine;
using System.Collections;
public class NGUIButtonEvent : MonoBehaviour {
void OnPress(bool isPress)
{
if(isPress)
{
print("按鈕按下");
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ButtonEvent : MonoBehaviour , IVirtualButtonEventHandler{
// Use this for initialization
void Start () {
VirtualButtonBehaviour[] btn = transform.GetComponentsInChildren<VirtualButtonBehaviour>();
// 著地判斷
public LayerMask isGroundedSlopeLayer;
public float isGroundedSlopeDis = 0.5f;
// 如果傳入 !isJumped 判斷是否在地面,於角色腳下斜後方打出射線來判斷
// 如果在斜坡上則返回true
// 如果不在斜坡上且角色控制器也不在地面則返回false
// 如果傳入 isJumped 判斷是否在斜面上,避免在斜面上無法操作一些動作或修正
// ex. 由於跳躍高度不夠快而黏在樓梯、由於樓梯上的重力不足而出現浮空狀態
bool isGroundedSlope(bool isJumped)
{
@smallrice45
smallrice45 / PlaneRayCast
Created April 26, 2014 14:41
Unity 向前方打出射線判斷是否為牆壁,並計算中心點。
using UnityEngine;
using System.Collections;
public class PlaneRayCast : MonoBehaviour {
// 射線長度
public float rayLength = 100;
// 射線擊中資訊
RaycastHit hit;
// 設定設線偵測圖層
public LayerMask wallLayer;
@smallrice45
smallrice45 / enemyMovement
Created June 18, 2014 14:04
練習Navmesh
using UnityEngine;
using System.Collections;
public class enemyMovement : MonoBehaviour {
NavMeshAgent agent;
void Start () {
agent = GetComponent< NavMeshAgent >();
}
using UnityEngine;
using System.Collections;
public class DestroySelf : MonoBehaviour {
public bool activeBool = false;
public TweenAlpha mTweenAlpha;
public TweenScale mTweenScale;
void Awake()
{
mTweenAlpha = GetComponent<TweenAlpha> ();
@smallrice45
smallrice45 / BackpackManager
Created May 22, 2015 11:03
Sample Backpack
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BackpackManager : MonoBehaviour {
public List<ItemData.ItemAttribute> _BackpackItem = new List<ItemData.ItemAttribute>();
public List<ItemData.ItemAttribute> m_BackpackItem {
get {
return _BackpackItem;
}