Skip to content

Commit 93934bf

Browse files
committed
シューティングゲーム改: 重力の働く弾と働かない弾を混ぜる
1 parent a9fa5e3 commit 93934bf

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Chapter8/Chapter8/ShootingLogic.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class ShootingLogic: ObservableObject {
6767
let bulletClone = bullet.clone(recursive: true)
6868
bulletClone.position = position
6969
bulletClone.physicsMotion?.linearVelocity = velocity
70+
// 重力が効くかを乱数で決める
71+
let g = Bool.random()
72+
bulletClone.physicsBody?.isAffectedByGravity = g
73+
// 重力が効くかによって色を変える
74+
var material = PhysicallyBasedMaterial()
75+
material.baseColor = .init(tint: g ? .green : .red, texture: nil)
76+
bulletClone.model?.materials = [material]
7077
bulletRoot.addChild(bulletClone)
7178
// アクションのコールバック
7279
shootAction()

0 commit comments

Comments
 (0)