-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.gd
41 lines (32 loc) · 1.08 KB
/
Player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extends Node
var car_scene = load("res://Scenes/Car.tscn")
var hover_craft_scene = load("res://Scenes/HoverCraft.tscn")
var current_vehicle
var current_vehicle_name
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
current_vehicle = car_scene.instance()
current_vehicle_name = "car"
add_child(current_vehicle)
func _input(event):
if event.is_action_pressed("switch"):
switch()
func switch():
var glob_trans = current_vehicle.global_transform
var lin_velocity = current_vehicle.linear_velocity
current_vehicle.queue_free()
if current_vehicle_name == "car":
current_vehicle = hover_craft_scene.instance()
current_vehicle_name = "hoverboard"
elif current_vehicle_name == "hoverboard":
current_vehicle = car_scene.instance()
current_vehicle_name = "car"
current_vehicle.global_transform = glob_trans
current_vehicle.linear_velocity = lin_velocity
add_child(current_vehicle)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass