-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
扉の開閉 #41
Closed
Closed
扉の開閉 #41
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0cf0b15
Interactメソッドから開閉メソッド
iieiieiie 91455b3
コメント追加
iieiieiie 778284b
扉の移動範囲を制限
iieiieiie 80084e6
Merge branch '_iieiieiie/door-open-close' of https://github.com/denx-…
iieiieiie 3abbcf5
itweenを使用したコード
iieiieiie f9f9648
itweenも追加
iieiieiie 304ae0b
シーン作成
iieiieiie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class DoorController : MonoBehaviour, IInteractable //IInteractableを継承 | ||
{ | ||
bool isOpen; //falseが閉まっている状態、trueが開いている状態 | ||
public Transform Stick; | ||
float timer; | ||
//Interactメソッドが呼ばれるとisOpen切り替え、trueかfalseでOpenかCloseのメソッド呼び出し | ||
public void Interact(PlayerManager playerManager) | ||
{ | ||
isOpen = !isOpen; | ||
if (isOpen) | ||
{ | ||
StartCoroutine("Open"); | ||
} | ||
else if (!isOpen) | ||
{ | ||
StartCoroutine("Close"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 14行目からここまでの処理はUpdateの中でやってください.( isOpenの値の監視は今回は一時的にUpdate内で行う) |
||
} | ||
void Start() | ||
{ | ||
isOpen = false; //最初は閉まっている | ||
timer = 0; | ||
var player = GameObject.Find("Player"); | ||
Stick = player.transform; | ||
} | ||
|
||
void Update() | ||
{ | ||
Debug.Log(isOpen); | ||
//Debug.Log(Stick.position); | ||
} | ||
|
||
private IEnumerator Close() | ||
{ | ||
for (int i = 0; ; i++) | ||
{ | ||
timer += Time.deltaTime; | ||
transform.position += new Vector3(10.0f, 0.0f, 0.0f); | ||
Debug.Log(transform.position); | ||
|
||
if (timer >= 0.5f)//2秒間実行? | ||
{ | ||
timer = 0; | ||
yield break; | ||
} | ||
yield return null; | ||
} | ||
|
||
} | ||
|
||
private IEnumerator Open() | ||
{ | ||
for(int i=0; ; i++) | ||
{ | ||
timer += Time.deltaTime; | ||
transform.position += new Vector3(-10.0f, 10.0f, 0.0f); | ||
Debug.Log(transform.position); | ||
|
||
if (timer >= 0.5f) | ||
{ | ||
timer = 0; | ||
yield break; | ||
} | ||
yield return null; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ドアの開閉命令はコルーチンではなく,メソッド(Open,Close)を作ってその中でやってください.
(isOpenの値が変化したらドアの開閉を行うメソッドを呼ぶ)
コルーチンを使う場合はOpen,Closeの中で開始するようにしてください