ステージの拡張1(ドアのオープン&クローズ)
![1e5945c9 67e0 4095 bd21 ade3387a519d](https://codegenius.org/uploads/slide/image/8384/1e5945c9-67e0-4095-bd21-ade3387a519d.jpeg)
![6337a3bb 6cc4 438d ad4c 2926345dfe7d](https://codegenius.org/uploads/slide/image/8385/6337a3bb-6cc4-438d-ad4c-2926345dfe7d.jpeg)
![996fe411 3a18 4891 b9e0 910fbc3fdfc8](https://codegenius.org/uploads/slide/image/8386/996fe411-3a18-4891-b9e0-910fbc3fdfc8.jpeg)
![313707bc 92d1 490e a889 83b30efaa0c5](https://codegenius.org/uploads/slide/image/8387/313707bc-92d1-490e-a889-83b30efaa0c5.jpeg)
![A883072f 8464 47fc 92d0 e3a1ce90c1d8](https://codegenius.org/uploads/slide/image/8388/a883072f-8464-47fc-92d0-e3a1ce90c1d8.jpeg)
ドアを動かす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorMove : MonoBehaviour
{
private Vector3 initialPos;
public float goalPos;
void Start()
{
initialPos = transform.position;
}
void Update()
{
// 今回はY方向に動くドアを想定
transform.position = Vector3.MoveTowards(transform.position, new Vector3(initialPos.x, goalPos, initialPos.z), Time.deltaTime);
}
}
![7ab29d9d b78c 4b51 b382 f4693e8e3c01](https://codegenius.org/uploads/slide/image/8389/7ab29d9d-b78c-4b51-b382-f4693e8e3c01.jpeg)
![7993723f cb75 4a32 a96d ce2298e2df39](https://codegenius.org/uploads/slide/image/8390/7993723f-cb75-4a32-a96d-ce2298e2df39.jpeg)
![41f12e4f 4452 4e13 a617 42b46e94883c](https://codegenius.org/uploads/slide/image/8391/41f12e4f-4452-4e13-a617-42b46e94883c.jpeg)
![B24a8162 4c37 437a b92f 23a1d27e68b0](https://codegenius.org/uploads/slide/image/8392/b24a8162-4c37-437a-b92f-23a1d27e68b0.jpeg)
![70b0c2d3 da83 4010 a2f1 5d5d5cca30d0](https://codegenius.org/uploads/slide/image/8393/70b0c2d3-da83-4010-a2f1-5d5d5cca30d0.jpeg)
![47c055f8 5214 47bb a52f c98439e5a9a7](https://codegenius.org/uploads/slide/image/8394/47c055f8-5214-47bb-a52f-c98439e5a9a7.jpeg)
![7d031ea6 4bfa 4eab b853 0699a8bdd95f](https://codegenius.org/uploads/slide/image/8395/7d031ea6-4bfa-4eab-b853-0699a8bdd95f.jpeg)
![1b9966ee 7846 4e7b 9e5d e6fdaf3e2b82](https://codegenius.org/uploads/slide/image/8396/1b9966ee-7846-4e7b-9e5d-e6fdaf3e2b82.jpeg)
センサーのスーパークラス
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 「abstract」キーワードの追加
public abstract class SensorBase : MonoBehaviour
{
public GameObject target;
public AudioClip sound;
public virtual void OnTriggerEnter(Collider other)
{
this.gameObject.SetActive(false); // センサーの使用は1回のみ
}
}
![Eb43e157 5726 4a97 97af 0283f007028a](https://codegenius.org/uploads/slide/image/8397/eb43e157-5726-4a97-97af-0283f007028a.jpeg)
センサーのサブクラス
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sensor1 : SensorBase // 変更
{
public override void OnTriggerEnter(Collider other)
{
base.OnTriggerEnter(other);
if (other.CompareTag("Player"))
{
AudioSource.PlayClipAtPoint(sound, Camera.main.transform.position);
target.GetComponent<DoorMove>().enabled = true;
}
}
}
![94c5e115 d86b 430c 9dd2 c19286ced4b6](https://codegenius.org/uploads/slide/image/8398/94c5e115-d86b-430c-9dd2-c19286ced4b6.jpeg)
![05e41a64 f2b3 4d71 9105 81ea377219a1](https://codegenius.org/uploads/slide/image/8399/05e41a64-f2b3-4d71-9105-81ea377219a1.jpeg)
![754eccad f1d6 4797 acba bc6c708f4561](https://codegenius.org/uploads/slide/image/8400/754eccad-f1d6-4797-acba-bc6c708f4561.jpeg)
【2021版】X_Mission(全34回)
他のコースを見る![1e5945c9 67e0 4095 bd21 ade3387a519d](https://codegenius.org/uploads/slide/image/8384/1e5945c9-67e0-4095-bd21-ade3387a519d.jpeg)
![6337a3bb 6cc4 438d ad4c 2926345dfe7d](https://codegenius.org/uploads/slide/image/8385/6337a3bb-6cc4-438d-ad4c-2926345dfe7d.jpeg)
![996fe411 3a18 4891 b9e0 910fbc3fdfc8](https://codegenius.org/uploads/slide/image/8386/996fe411-3a18-4891-b9e0-910fbc3fdfc8.jpeg)
![313707bc 92d1 490e a889 83b30efaa0c5](https://codegenius.org/uploads/slide/image/8387/313707bc-92d1-490e-a889-83b30efaa0c5.jpeg)
![A883072f 8464 47fc 92d0 e3a1ce90c1d8](https://codegenius.org/uploads/slide/image/8388/a883072f-8464-47fc-92d0-e3a1ce90c1d8.jpeg)
ドアを動かす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorMove : MonoBehaviour
{
private Vector3 initialPos;
public float goalPos;
void Start()
{
initialPos = transform.position;
}
void Update()
{
// 今回はY方向に動くドアを想定
transform.position = Vector3.MoveTowards(transform.position, new Vector3(initialPos.x, goalPos, initialPos.z), Time.deltaTime);
}
}
![7ab29d9d b78c 4b51 b382 f4693e8e3c01](https://codegenius.org/uploads/slide/image/8389/7ab29d9d-b78c-4b51-b382-f4693e8e3c01.jpeg)
![7993723f cb75 4a32 a96d ce2298e2df39](https://codegenius.org/uploads/slide/image/8390/7993723f-cb75-4a32-a96d-ce2298e2df39.jpeg)
![41f12e4f 4452 4e13 a617 42b46e94883c](https://codegenius.org/uploads/slide/image/8391/41f12e4f-4452-4e13-a617-42b46e94883c.jpeg)
![B24a8162 4c37 437a b92f 23a1d27e68b0](https://codegenius.org/uploads/slide/image/8392/b24a8162-4c37-437a-b92f-23a1d27e68b0.jpeg)
![70b0c2d3 da83 4010 a2f1 5d5d5cca30d0](https://codegenius.org/uploads/slide/image/8393/70b0c2d3-da83-4010-a2f1-5d5d5cca30d0.jpeg)
![47c055f8 5214 47bb a52f c98439e5a9a7](https://codegenius.org/uploads/slide/image/8394/47c055f8-5214-47bb-a52f-c98439e5a9a7.jpeg)
![7d031ea6 4bfa 4eab b853 0699a8bdd95f](https://codegenius.org/uploads/slide/image/8395/7d031ea6-4bfa-4eab-b853-0699a8bdd95f.jpeg)
![1b9966ee 7846 4e7b 9e5d e6fdaf3e2b82](https://codegenius.org/uploads/slide/image/8396/1b9966ee-7846-4e7b-9e5d-e6fdaf3e2b82.jpeg)
センサーのスーパークラス
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 「abstract」キーワードの追加
public abstract class SensorBase : MonoBehaviour
{
public GameObject target;
public AudioClip sound;
public virtual void OnTriggerEnter(Collider other)
{
this.gameObject.SetActive(false); // センサーの使用は1回のみ
}
}
![Eb43e157 5726 4a97 97af 0283f007028a](https://codegenius.org/uploads/slide/image/8397/eb43e157-5726-4a97-97af-0283f007028a.jpeg)
センサーのサブクラス
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sensor1 : SensorBase // 変更
{
public override void OnTriggerEnter(Collider other)
{
base.OnTriggerEnter(other);
if (other.CompareTag("Player"))
{
AudioSource.PlayClipAtPoint(sound, Camera.main.transform.position);
target.GetComponent<DoorMove>().enabled = true;
}
}
}
![94c5e115 d86b 430c 9dd2 c19286ced4b6](https://codegenius.org/uploads/slide/image/8398/94c5e115-d86b-430c-9dd2-c19286ced4b6.jpeg)
![05e41a64 f2b3 4d71 9105 81ea377219a1](https://codegenius.org/uploads/slide/image/8399/05e41a64-f2b3-4d71-9105-81ea377219a1.jpeg)
![754eccad f1d6 4797 acba bc6c708f4561](https://codegenius.org/uploads/slide/image/8400/754eccad-f1d6-4797-acba-bc6c708f4561.jpeg)
ステージの拡張1(ドアのオープン&クローズ)