質問編集履歴

10

2020/12/06 12:09

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
File without changes

9

2020/12/06 12:09

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
  audioSource.clip=sound;
48
48
 
49
- AudioSource.Play();
49
+ AudioSource.Stop();
50
50
 
51
51
 
52
52
 

8

2020/12/06 04:35

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  {
32
32
 
33
- if (collision.gameObject.name==''Cube1''){
33
+ if (collision.gameObject.name==Cube1){
34
34
 
35
35
  audioSource.clip=sound;
36
36
 
@@ -40,7 +40,7 @@
40
40
 
41
41
  private void OnCollisionExit(Collision collision){
42
42
 
43
- if (collision.gameObject.name==''Cube1''){
43
+ if (collision.gameObject.name==Cube1){
44
44
 
45
45
 
46
46
 

7

2020/12/06 04:34

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,32 +1,58 @@
1
- 特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。```using UnityEngine;

1
+ 特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。```using UnityEngine;

2
+
3
+
4
+
5
+ ```using UnityEngine;
2
6
 
3
7
  using System.Collections;
4
8
 
5
- 

public class Sound : MonoBehaviour{


6
9
 
7
- public AudioClip sound;

8
10
 
9
- private AudioSource audioSource;


11
+ public class Sound : MonoBehaviorce;

 {
10
12
 
11
- void Start()

12
13
 
13
- {

14
14
 
15
- audioSource = GetComponent<AudioSource>();
 }


15
+ public AudioClip sound;
 }


16
16
 
17
- private void OnCollisionEnter(Collision collision)
 {

17
+ private AudioSource audioSourcollision)
 {
 e;
18
18
 
19
- if (collision.gameObject.name == "Cube1") { audioSource.clip = sound;
 
 audioSource.Play();

20
19
 
21
- }


22
20
 
23
- private void OnCollisionExit(Collision collision)
 {

21
+ void Start()
 {

24
22
 
25
- if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;

 audioSource.Stop();

23
+ {

 audioSource.clip = sound;

 audioSource.Stop();

26
24
 
27
- }

25
+ }
 AudioSource=GetComponent<AudioSource>();
28
26
 
29
- }
27
+ }
28
+
29
+ private void OnCollisionEnter (Collision collision)
30
+
31
+ {
32
+
33
+ if (collision.gameObject.name==''Cube1''){
34
+
35
+ audioSource.clip=sound;
36
+
37
+ AudioSource.Play();
38
+
39
+ }
40
+
41
+ private void OnCollisionExit(Collision collision){
42
+
43
+ if (collision.gameObject.name==''Cube1''){
44
+
45
+
46
+
47
+ audioSource.clip=sound;
48
+
49
+ AudioSource.Play();
50
+
51
+
52
+
53
+ }
54
+
55
+ }
30
56
 
31
57
  }
32
58
 

6

2020/12/05 06:27

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。````````````using UnityEngine;

1
+ 特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。```using UnityEngine;

2
2
 
3
3
  using System.Collections;
4
4
 

5

2020/12/05 06:09

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,4 @@
1
- 特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。````````````using UnityEngine;

1
+ 特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。````````````using UnityEngine;

2
-
3
- `````````using UnityEngine;

4
2
 
5
3
  using System.Collections;
6
4
 
@@ -32,9 +30,7 @@
32
30
 
33
31
  }
34
32
 
35
- コード
36
33
 
37
- ```
38
34
 
39
35
  コード
40
36
 

4

2020/12/05 06:07

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,9 +1,41 @@
1
1
  特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。
2
2
 
3
+ `````````using UnityEngine;

3
4
 
5
+ using System.Collections;
4
6
 
5
- ``````using UnityEngine;using System.Collections;public class Sound : MonoBehaviour{

 public AudioClip sound;
 private AudioSource audioSource;

 void Start()
 {
 audioSource = GetComponent<AudioSource>();
 }

 private void OnCollisionEnter(Collision collision)
 {
 if (collision.gameObject.name == "Cube ) audioSource.clip = sound;
 
 audioSource.Play();
 }

 private void OnCollisionExit(Collision collision)
 {
 if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;

 audioSource.Stop();
 }
 }
}
7
+ 

public class Sound : MonoBehaviour{

 public AudioClip sound;
 private AudioSource audioSource;

 void Start()
 {
 audioSource = GetComponent<AudioSource>();
 }

 private void OnCollisionEnter(Collision collision)
 {
 if (collision.gameObject.name == "Cube ) audioSource.clip = sound;
 
 audioSource.Play();
 }

 private void OnCollisionExit(Collision collision)
 {
 if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;

 audioSource.Stop();
 }
 }
}
8
+
9
+ public AudioClip sound;

10
+
11
+ private AudioSource audioSource;


12
+
13
+ void Start()

14
+
15
+ {

16
+
17
+ audioSource = GetComponent<AudioSource>();
 }


18
+
19
+ private void OnCollisionEnter(Collision collision)
 {

20
+
21
+ if (collision.gameObject.name == "Cube1") { audioSource.clip = sound;
 
 audioSource.Play();

22
+
23
+ }


24
+
25
+ private void OnCollisionExit(Collision collision)
 {

26
+
27
+ if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;

 audioSource.Stop();

28
+
29
+ }

30
+
31
+ }

32
+
33
+ }
6
34
 
7
35
  コード
8
36
 
9
37
  ```
38
+
39
+ コード
40
+
41
+ ```

3

2020/12/05 06:06

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,12 +1,8 @@
1
1
  特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。
2
2
 
3
- ```using UnityEngine;
using System.Collections;

public class Sound : MonoBehaviour{

 public AudioClip sound;
 private AudioSource audioSource;

 void Start()
 {
 audioSource = GetComponent<AudioSource>();
 }

 private void OnCollisionEnter(Collision collision)
 {
 if (collision.gameObject.name == "Cube1") {
 
 audioSource.clip = sound;
 
 audioSource.Play();
 }

 private void OnCollisionExit(Collision collision)
 {
 if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;
4
-
5
- audioSource.stop();
6
-
7
- 
 }
 }
}

8
3
 
9
4
 
5
+ ``````using UnityEngine;
using System.Collections;

public class Sound : MonoBehaviour{

 public AudioClip sound;
 private AudioSource audioSource;

 void Start()
 {
 audioSource = GetComponent<AudioSource>();
 }

 private void OnCollisionEnter(Collision collision)
 {
 if (collision.gameObject.name == "Cube ) audioSource.clip = sound;
 
 audioSource.Play();
 }

 private void OnCollisionExit(Collision collision)
 {
 if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;

 audioSource.Stop();
 }
 }
}
10
6
 
11
7
  コード
12
8
 

2

2020/12/05 04:41

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。
2
2
 
3
- `````using UnityEngine;
using System.Collections;

public class Sound : MonoBehaviour{

 public AudioClip sound;
 private AudioSource audioSource;

 void Start()
 {
 audioSource = GetComponent<AudioSource>();
 }

 private void OnCollisionEnter(Collision collision)
 {
 if (collision.gameObject.name == "Cube1") {
 
 audioSource.clip = sound;
 
 audioSource.Play();
 }

 private void OnCollisionExit(Collision collision)
 {
 if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;
3
+ ```using UnityEngine;
using System.Collections;

public class Sound : MonoBehaviour{

 public AudioClip sound;
 private AudioSource audioSource;

 void Start()
 {
 audioSource = GetComponent<AudioSource>();
 }

 private void OnCollisionEnter(Collision collision)
 {
 if (collision.gameObject.name == "Cube1") {
 
 audioSource.clip = sound;
 
 audioSource.Play();
 }

 private void OnCollisionExit(Collision collision)
 {
 if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;
4
4
 
5
5
  audioSource.stop();
6
6
 

1

2020/12/05 04:36

投稿

chami
chami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,12 @@
1
1
  特定のオブジェクト(Cube1)に触れている時だけ音を鳴らしたいのですが、そのオブジェクトを離れても音がなり止みません。
2
2
 
3
+ `````using UnityEngine;
using System.Collections;

public class Sound : MonoBehaviour{

 public AudioClip sound;
 private AudioSource audioSource;

 void Start()
 {
 audioSource = GetComponent<AudioSource>();
 }

 private void OnCollisionEnter(Collision collision)
 {
 if (collision.gameObject.name == "Cube1") {
 
 audioSource.clip = sound;
 
 audioSource.Play();
 }

 private void OnCollisionExit(Collision collision)
 {
 if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;
4
+
5
+ audioSource.stop();
6
+
7
+ 
 }
 }
}

3
8
 
4
9
 
5
- ``using UnityEngine;
using System.Collections;

public class Sound : MonoBehaviour{

 public AudioClip sound;
 private AudioSource audioSource;

 void Start()
 {
 audioSource = GetComponent<AudioSource>();
 }

 private void OnCollisionEnter(Collision collision)
 {
 if (collision.gameObject.name == "Cube1") {
 
 audioSource.clip = sound;
 
 audioSource.Play();
 }

 private void OnCollisionExit(Collision collision)
 {
 if (collision.gameObject.name == "Cube1"){

 audioSource.clip = sound;

 audioSource.Stop();
 }
 }
}

6
10
 
7
11
  コード
8
12