C#_Unity_逆引き01
■Lerp
直線上にある2つのベクトル間を補間する関数
https://qiita.com/aimy-07/items/ad0d99191da21c0adbc3
■DefaultExecutionOrder(-1)
【Unity】DefaultExecutionOrderでスクリプトの実行順番をスクリプトから書く - はなちるのマイノート
■RequireComponent(typeof(NavMeshAgent))
コンポーネントを自動的にアタッチ
[Unity初心者Tips]確実に!必要なComponentを入れるRequire ComponentとReset() - Qiita
■Instantiate
クローン生成
https://www.sejuku.net/blog/48180
★色を変える
void Update() { if (Input.GetKeyDown(KeyCode.R)) { GetComponent<Renderer> ().material.color = Color.red; }
★引数、戻り値など
int myInt = 5; void Start () { myInt = MultiplyByTwo(myInt); Debug.Log (myInt); } int MultiplyByTwo (int number) { int result; result = number * 2; return result; }
https://xr-hub.com/archives/8154
★if文
■loop文
https://3dunity.org/unity-introduction/unity-csharp-programming/loop-sentence-for-while-foreach/
■Jump
■PS4のコントローラー
https://qiita.com/o_s_t/items/c18edeeee869d42c6eb9
■InvokeRepeating
x秒に関数を呼び出して、y秒ごとに繰り返し呼び出す
https://www.sejuku.net/blog/83762
■カメラ固定(横スクロールゲーム)
https://miyagame.net/yoko-scroll-camera/
■敵│移動
https://dkrevel.com/makegame-beginner/make-2d-action-enemy-move/
https://www.youtube.com/watch?v=NbA95f1FlXQ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public float dirX;
public float moveSpeed;
public Rigidbody rb;
public bool facingRight = false;
public Vector3 localScale;
// Start is called before the first frame update
void Start()
{
localScale = transform.localScale;
rb = GetComponent<Rigidbody>();
dirX = -1f;
moveSpeed = 3f;
}
private void OnTriggerEnter(Collider other)
{
if(other.GetComponent<WALLL>())
{
dirX *= -1f;
}
}
private void FixedUpdate()
{
rb.velocity = new Vector3(dirX * moveSpeed, rb.velocity.y);
}
// Update is called once per frame
void LateUpdate()
{
CheckWhereToFace();
}
void CheckWhereToFace()
{
if (dirX > 0)
facingRight = true;
else if (dirX < 0)
facingRight = false;
if (((facingRight) && (localScale.x <0)) || ((!facingRight) && (localScale.x > 0)))
localScale.x *= -1;
transform.localScale = localScale;
}
}