-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveplat.cs
103 lines (94 loc) · 2.91 KB
/
moveplat.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveplat : MonoBehaviour {
public float x;
public float y;
public float z;
public float xdist;
public float ydist;
public float zdist;
float xcount;
float ycount;
float zcount;
GameObject player;
bool standing;
public bool activated;
Vector3 previousposition;
//public UnityEngine.UI.Text st;
// Use this for initialization
void Start () {
standing = false;
// st.text = "no";
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
// other.transform.parent = null;
standing = true;
player = other.gameObject;
//other.gameObject.transform.SetParent(gameObject.transform, true);*/
activated = true;
//st.text = "yes";
}
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
// other.transform.parent = null;
standing = true;
player = other.gameObject;
//other.gameObject.transform.SetParent(gameObject.transform, true);*/
activated = true;
//st.text = "yes";
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
if (standing == true)
{
standing = false;
//other.transform.parent = null;
}
//playermovement.moveDirection.x += x;
//playermovement.moveDirection.z += z;
}
}
// Update is called once per frame
void FixedUpdate()
{
if (activated)
{
xcount += x;
ycount += y;
zcount += z;
if (xcount >= xdist || xcount <= -xdist)
{
x = -x;
xcount = 0;
}
if (ycount >= ydist || ycount <= -ydist)
{
y = -y;
ycount = 0;
}
if (zcount >= zdist || zcount <= -zdist)
{
z = -z;
zcount = 0;
}
previousposition = gameObject.transform.position;
gameObject.transform.Translate(x, y, z);
if (standing == true)
{
//player.GetComponent<CharacterController>().Move(gameObject.transform.position - previousposition);
Vector3 moveamount = gameObject.transform.position - previousposition;
player.transform.position = new Vector3(player.gameObject.transform.position.x + moveamount.x, player.gameObject.transform.position.y + moveamount.y, player.gameObject.transform.position.z + moveamount.z);
}
}
}
}