段差を登るシステムを作っていたのですが、
スクリプトからgetcomponentしようとすると、
c:\Users\user\Documents\New Unity Project 3\Assets\Standard Assets\Characters\ThirdPersonCharacter\Scripts\ThirdPersonCharacter.cs(4,4): Error CS0246: 型または名前空間名 'dansacollider1' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足しています。 (CS0246) (Assembly-CSharp-firstpass)
とでてビルドエラーになります。
・構造
・Thirdpersoncontroller
・モデル
・dansacolloder1
・dansacolloder2
・dansacolloder3
・dansacolloder4
・dansacolloder5
・スクリプト
・thirdpersoncontroller.cs
using UnityEngine;
using System.Collections;
namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(CapsuleCollider))]
[RequireComponent(typeof(Animator))]
public class ThirdPersonCharacter : MonoBehaviour
{
[SerializeField] float m_MovingTurnSpeed = 360;
[SerializeField] float m_StationaryTurnSpeed = 180;
[SerializeField] float m_JumpPower = 12f;
[Range(1f, 4f)][SerializeField] float m_GravityMultiplier = 2f;
[SerializeField] float m_RunCycleLegOffset = 0.2f; //specific to the character in sample assets, will need to be modified to work with others
[SerializeField] float m_MoveSpeedMultiplier = 1f;
[SerializeField] float m_AnimSpeedMultiplier = 1f;
[SerializeField] float m_GroundCheckDistance = 0.1f;
Rigidbody m_Rigidbody;
Animator m_Animator;
bool m_IsGrounded;
float m_OrigGroundCheckDistance;
const float k_Half = 0.5f;
float m_TurnAmount;
float m_ForwardAmount;
Vector3 m_GroundNormal;
float m_CapsuleHeight;
Vector3 m_CapsuleCenter;
CapsuleCollider m_Capsule;
bool m_Crouching;
//段差システム
bool dansatrigger = false;
bool dc1 = false;
bool dc2 = false;
bool dc3 = false;
bool dc4 = false;
bool dc5 = false;
void Start()
{
m_Animator = GetComponent<Animator>();
m_Rigidbody = GetComponent<Rigidbody>();
m_Capsule = GetComponent<CapsuleCollider>();
m_CapsuleHeight = m_Capsule.height;
m_CapsuleCenter = m_Capsule.center;
m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
m_OrigGroundCheckDistance = m_GroundCheckDistance;
//段差システム
}
public void update()
{
//段差システム
var f_dc1 = GameObject.Find("dansacollider1");
dansacollider1 g_dc1 = f_dc1.GetComponent<dansacollider1>();
g_dc1.dansatrigger1 = dc1;
var f_dc2 = GameObject.Find("dansacollider2");
dansacollider1 g_dc2 = f_dc2.GetComponent<dansacollider2>();
g_dc2.dansatrigger2 = dc2;
var f_dc3 = GameObject.Find("dansacollider3");
dansacollider3 g_dc3 = f_dc3.GetComponent<dansacollider3>();
g_dc3.dansatrigger3 = dc3;
var f_dc4 = GameObject.Find("dansacollider4");
dansacollider4 g_dc4 = f_dc4.GetComponent<dansacollider4>();
g_dc4.dansatrigger4 = dc4;
var f_dc5 = GameObject.Find("dansacollider5");
dansacollider5 g_dc5 = f_dc5.GetComponent<dansacollider5>();
g_dc5.dansatrigger5 = dc5;
if (dc1){
//段差1処理
m_Animator.SetFloat("dansaheight",1);
dansatrigger = true;
if(dc2){
//段差2処理
m_Animator.SetFloat("dansaheight",2);
dansatrigger = true;
if(dc3){
//段差3処理
m_Animator.SetFloat("dansaheight",3);
dansatrigger = true;
if(dc4){
//段差4処理
m_Animator.SetFloat("dansaheight",4);
dansatrigger = true;
if(dc5){
//段差5処理
m_Animator.SetFloat("dansaheight",5);
dansatrigger = true;
}
}
}
}
}
else{
dansatrigger = false;
}
}
・dansacollider1~5
using UnityEngine;
using System.Collections;
public class dansacollider1 : MonoBehaviour {
public bool dansatrigger1;
// Use this for initialization
public void Start () {
dansatrigger1 = false;
}
// 衝突した瞬間に呼ばれる
public void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "dansa"){
dansatrigger1 = true;
}
}
// 衝突から離れた瞬間に呼ばれる
public void OnTriggerExit(Collider other) {
if (other.gameObject.tag == "dansa") {
dansatrigger1 = false;
}
}
// Update is called once per frame
void Update () {
}
}