-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdamHareket.cs
More file actions
89 lines (75 loc) · 2.11 KB
/
AdamHareket.cs
File metadata and controls
89 lines (75 loc) · 2.11 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AdamHareket : MonoBehaviour
{
public float hiz = 6.0f;
public float ziplama = 8.0f;
public float yerCekimi = 20.0f;
bool yonSag = true;
CharacterController cc;
Animator anim;
Vector3 hareket = Vector3.zero;
Vector3 baslangic;
void Start()
{
cc = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
baslangic = cc.transform.position;
if (cc == null)
{
Debug.LogError("CharacterController ekli değil!");
}
if (anim == null)
{
Debug.LogError("Animator ekli değil!");
}
}
void Update()
{
if(Input.GetKey(KeyCode.R))
{
cc.enabled = false;
cc.transform.position = baslangic;
cc.enabled = true;
}
if (cc.isGrounded)
{
hareket = new Vector3(Input.GetAxis("Horizontal"), 0.0f, 0.0f);
hareket *= hiz;
if(hareket.x != 0.0f)
{
anim.SetBool("yuru", true);
}
else
{
anim.SetBool("yuru", false);
}
if (Input.GetButton("Jump"))
{
hareket.y = ziplama;
anim.SetBool("zipla", true);
}
else
{
anim.SetBool("zipla", false);
}
}
else
{
hareket.x += Mathf.Clamp(Input.GetAxis("Horizontal") * hiz,-hiz * 1.1f,hiz * 1.1f) * Time.deltaTime;
hareket.y -= yerCekimi * Time.deltaTime;
}
if(hareket.x > 0f)
{
yonSag = true;
gameObject.transform.SetPositionAndRotation(gameObject.transform.position, Quaternion.Euler(0, 0, 0));
}
else if(hareket.x < 0f)
{
yonSag = false;
gameObject.transform.SetPositionAndRotation(gameObject.transform.position, Quaternion.Euler(0, 180, 0));
}
cc.Move(hareket * Time.deltaTime);
}
}