unity isTrigger チェックボックスをスクリプトで切り替え (c#
上記の質問を参考にしてisTriggerを変更するスクリプトを書きました。
しかし、エラーが3種類出ていて困っています。
ご教授願います。
↓3つのエラー
Assets/Scripts/EnemyController.cs(22,3): error CS1604: Cannot assign to `this' because it is read-only
Assets/Scripts/EnemyController.cs(22,10): error CS0029: Cannot implicitly convert type
UnityEngine.Collider2D' to
EnemyController'
Assets/Scripts/EnemyController.cs(27,8): error CS1061: Type
EnemyController' does not contain a definition for
isTrigger' and no extension methodisTrigger' of type
EnemyController' could be found. Are you missing an assembly reference?
↓スクリプト
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class EnemyController : MonoBehaviour { 6 private Rigidbody2D rb2D; 7 private float jumpForce = 40f; 8 9 void OnCollisionEnter2D(Collision2D other) { 10 if (other.gameObject.tag == "Player") { 11 Jump (); 12 } 13 } 14 15 void Start () { 16 this = GetComponent<Collider2D>(); 17 rb2D = GetComponent<Rigidbody2D>(); 18 } 19 20 void Jump(){ 21 this.isTrigger = true; 22 rb2D.velocity = new Vector2(rb2D.velocity.y, jumpForce); 23 } 24}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/27 10:19