Unity Koddaki hata nedir?

Sebebi92

Decapat
Katılım
21 Ekim 2023
Mesajlar
209
Daha fazla  
Sistem Özellikleri
Ön Bellek 24 MB
İşlemci Hızı 2,30 GHz
İşlemci Türü Core™ i7
İşlemci Modeli i7-11800H
İşlemci Çekirdeği 8 Çekirdek
64 bit İşlem Var
İşlemci İmalatçısı Intel®
Maksimum Turbo Hız 4,60 GHz
İşlemci Nesli 11. Nesil
Optik Sürücü Türü Yok
Katı Hal Sürücü Ara Yüzü PCI Express
Katı Hal Sürücü Yapılandırması 1 x 512GB
Toplam Katı Hal Sürücüsü Kapasitesi 512 GB
Standart Yenileme Hızı 144 Hz
Grafik Denetleyici İmalatçısı NVIDIA®
Cinsiyet
Erkek
1750693372923.png


Hata bu kod.

Using unityengine;
Using unityengine. Inputsystem;

Public class playercontroller: Monobehaviour.
{
Charactercontroller Controller;
Playercontrols playercontrols;
Camera playeracağımera;

[Header("Movement")]
Public float walkspeed = 5F, sprintspeed = 8F, crouchspeed = 2.5F;
Public float jumpheight = 1.5F, gravity = -9.81F;
Vector3 velocity;
Bool isgrounded, iscrouching;
Float origh;
Vector3 origc;
Public float crouchh = 0.9F;

[Header("Aiming")]
Public float deffov = 60F, aimfov = 30F, aimspeed = 10F;
Bool isaiming;

[Header("Shooting")]
Public transform firepoint;
Public layermask shootmask;
Public float firerate = 0.1F, shootdist = 100F;
Float nextfire;

[Header("Weapons")]
Public gameobject[] weapons;
int wIdx;

[Header("Abilities")]
Public float cdbasic = 5F, cdsig = 10F, cdtok = 15F, cdult = 60F;
Float lastbasic = -mathf. Infinity, lastsig = -mathf. Infinity;
Float lasttok = -mathf. Infinity, lastult = -mathf. Infinity;

Void Awake()
{
Controller = GetComponent<CharacterController>();
Playeracağımera = camera. Main;
Origh = Controller. Height;
Origc = Controller. Center;

Playercontrols = New PlayerControls();

InitializeWeapons();

Var p = playercontrols. Player;

P. Jump. Performed += _ => Jump();
P. Crouch. Performed += _ => Crouch();
P. Crouch. Canceled += _ => StandUp();
P. Aim. Performed += _ => isaiming = true;
P. Aim. Canceled += _ => isaiming = false;
P. Changeweapon. Performed += ctx => ChangeWeapon(ctx.ReadValue<Vector2>());
P. Ability_basic. Performed += _ => UseBasic();
P. Ability_signature. Performed += _ => UseSig();
P. Ability_token. Performed += _ => UseTok();
P. Ability_ultimate. Performed += _ => UseUlt();
}

Void OnEnable()
{
playerControls.Player.Enable();
}

Void OnDisable()
{
playerControls.Player.Disable();

Var p = playercontrols. Player;
P. Jump. Performed -= _ => Jump();
P. Crouch. Performed -= _ => Crouch();
P. Crouch. Canceled -= _ => StandUp();
P. Aim. Performed -= _ => isaiming = true;
P. Aim. Canceled -= _ => isaiming = false;
P. Changeweapon. Performed -= ctx => ChangeWeapon(ctx.ReadValue<Vector2>());
P. Ability_basic. Performed -= _ => UseBasic();
P. Ability_signature. Performed -= _ => UseSig();
P. Ability_token. Performed -= _ => UseTok();
P. Ability_ultimate. Performed -= _ => UseUlt();
}

Void Update()
{
İsgrounded = Controller. İsgrounded;
İf (isgrounded && velocity. Y < 0) velocity. Y = -2F;

Vector2 mv = playerControls.Player.Move.ReadValue<Vector2>();
Vector3'dir = transform. Right * mv. X + transform. Forward * mv. Y;

Float SPD = walkspeed;
İf (playerControls.Player.Sprint.IsPressed())
SPD = iscrouching? Crouchspeed: Sprintspeed;
Else if (iscrouching) SPD = crouchspeed;

Controller. Move(dir * SPD * time. Deltatime);

Velocity. Y += gravity * time. Deltatime;
Controller. Move(velocity * time. Deltatime);

İf (playeracağımera)
{
Float tgt = isaiming? Aimfov: Deffov;
Playeracağımera. Fieldofview = mathf. Lerp(playeracağımera. Fieldofview, tgt, aimspeed * time. Deltatime);
}

İf (playerControls.Player.Fire.IsPressed() && Time.time >= nextFire)
{
Shoot();
Nextfire = time. Time + 1F / firerate;
}
}

Void Jump()
{
İf (isgrounded) velocity. Y = mathf. Sqrt(jumpheight * -2F * gravity);
Debug.Log("zıpladı!");
}

Void Crouch()
{
İf (!iscrouching)
{
İscrouching = true;
Controller. Height = crouchh;
Controller. Center = New Vector3(origc. X, crouchh / 2F, origc. Z);
Debug.Log("eğildi!");
}
Else.
{
StandUp();
}
}

Void StandUp()
{
İf (!iscrouching) return;

Vector3 rayorigin = transform. Position + Controller. Center;
Float raydistance = origh - crouchh + 0.1F;

İf (physics. Raycast(rayorigin, Vector3.up, raydistance, shootmask))
{
Debug.Log("üstte engel var, kalkılamıyor.");
Return;
}

İscrouching = false;
Controller. Height = origh;
Controller. Center = origc;
Debug.Log("ayağa kalktı!");
}

Void Shoot()
{
İf (firepoint == null)
{
Debug.Logwarning("firepoint (ateş noktası) belirlenmemiş! Inspector'da atayın.");
Return;
}
Raycasthit h;
İf (physics. Raycast(playeracağımera. Transform. Position, playeracağımera. Transform. Forward,
Out H, shootdist, shootmask))
{
Debug.Log("vurulan: " + h. Transform. Name + " at " + h. Point);
}
Else.
{
Debug.Log("hiçbir yere isabet etmedi.");
}
}

Private Void InitializeWeapons()
{
İf (weapons == null || weapons. Length == 0)
{
Debug.Logwarning("weapon models dizisi boş veya null! Hiçbir silah modeli atanmamış. Inspector'dan atayın.");
Return;
}

For (int i = 0; i < weapons. Length; i++)
{
İf (weapons!= null)
weapons.setactive(false);
}

if (weapons[wIdx]!= null)
{
weapons[wIdx].setactive(true);
Debug.Log("başlangıç silahı: " + weapons[wIdx].name);
}
}

Void changeweapon(Vector2 s)
{
if (weapons == null || weapons. Length == 0) return;

if (wıdx >= 0 && wıdx < weapons. Length && weapons[wIdx]!= null)
{
weapons[wIdx].setactive(false);
}

if (s. Y > 0)
wıdx = (wıdx + 1) % weapons. Length;
else if (s. Y < 0)
wıdx = (wıdx - 1 + weapons. Length) % weapons. Length;

if (wıdx >= 0 && wıdx < weapons. Length && weapons[wIdx]!= null)
{
weapons[wIdx].setactive(true);
Debug.Log("silah değiştirildi: " + weapons[wIdx].name);
}
}

Void UseBasic()
{
if (time. Time - lastbasic >= cdbasic)
{
lastbasic = time. Time;
Debug.Log("temel yetenek kullanıldı!");
}
else { Debug.Log("temel yetenek beklemede. Kalan süre: " + (cdbasic - (time. Time - lastbasic)).tostring("F1") + "s"); }
}

Void UseSig()
{
if (time. Time - lastsig >= cdsig)
{
lastsig = time. Time;
Debug.Log("imza yetenek kullanıldı!");
}
else { Debug.Log("imza yetenek beklemede. Kalan süre: " + (cdsig - (time. Time - lastsig)).tostring("F1") + "s"); }
}

Void UseTok()
{
if (time. Time - lasttok >= cdtok)
{
lasttok = time. Time;
Debug.Log("jetonlu yetenek kullanıldı!");
}
else { Debug.Log("jetonlu yetenek beklemede. Kalan süre: " + (cdtok - (time. Time - lasttok)).tostring("F1") + "s"); }
}

Void UseUlt()
{
if (time. Time - lastult >= cdult)
{
lastult = time. Time;
Debug.Log("Ultimate yetenek kullanıldı!");
}
else { Debug.Log("Ultimate yetenek beklemede. Kalan süre: " + (cdult - (time. Time - lastult)).tostring("F1") + "s"); }
}
}

Yapay zekaya falan da sordumda bir çözüm bulamadı
 
Son düzenleme:
Büyük küçük harflerden anlaşılmıyor ama muhtemelen PlayerControls class adıyla PlayerControls değişkeni bi yerde yanlış yorumlanıyor ve class değişken yerine ya da değişken class yerine kullanılıyor. Hatanın olduğu kısmın ss ini ve kodu büyük küçük harfi bozmadan atabilir misiniz?
 

Technopat Haberler

Yeni konular

Geri
Yukarı