Help I don’t know what to do
Assets\scripts\Player.cs(126,13): error CS0120: An object reference is required for the non-static field, method, or property ‘Weapon.RefreshAmmo(Text)’
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using Photon.Pun;
namespace RhinoRunnerGaming
{
public class Player : MonoBehaviourPunCallbacks
{
#region Variables
public float speed;
public float sprintModifier;
public Camera playerCamera;
public GameObject cameraParent;
public float jumpForce;
public int maxHealth;
public Transform weaponParent;
public Transform groundDetector;
public LayerMask ground;
private Transform ui_healthbar;
private Text ui_ammo;
private Rigidbody rig;
private Vector3 targetWeaponBobPosition;
private Vector3 weaponParentOrgin;
private float movementCounter;
private float idleCounter;
private float baseFOV;
private float sprintFOVModifier = 1.5f;
private int currentHealth;
private Manager manager;
private Weapon weapon;
#endregion
#region Monobehaivier Callbacks
void Start()
{
manager = GameObject.Find("Manager").GetComponent<Manager>();
weapon = GetComponent<Weapon>();
currentHealth = maxHealth;
if (photonView.IsMine)
{
gameObject.layer = 8;
}
cameraParent.SetActive(photonView.IsMine);
baseFOV = playerCamera.fieldOfView;
rig = GetComponent<Rigidbody>();
weaponParentOrgin = weaponParent.localPosition;
if (photonView.IsMine)
{
ui_healthbar = GameObject.Find("HUD/Health/Bar").transform;
ui_ammo = GameObject.Find("Hud/Ammo/Text").GetComponent<Text>();
RefreshHealthBar();
}
}
private void Update()
{
//Axis
float t_hmove = Input.GetAxisRaw("Horizontal");
float t_vmove = Input.GetAxisRaw("Vertical");
//Controls
bool sprint = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
bool jump = Input.GetKeyDown(KeyCode.Space);
//States
bool isGrounded = Physics.Raycast(groundDetector.position, Vector3.down, 1f, ground);
bool isJumping = jump && isGrounded;
bool isSprinting = sprint && t_vmove > 0 && !jump;
//Jumping
if (jump && isGrounded)
{
rig.AddForce(Vector3.up * jumpForce);
}
if (Input.GetKeyDown(KeyCode.U))
{
TakeDamage(100);
}
//Head Bob
if (t_hmove == 0 && t_vmove == 0)
{
HeadBob(idleCounter, 0.025f, 0.025f);
idleCounter += Time.deltaTime;
weaponParent.localPosition = Vector3.Lerp(weaponParent.localPosition, targetWeaponBobPosition, Time.deltaTime * 2f);
}
else if (!isSprinting)
{
HeadBob(movementCounter, 0.035f, 0.035f);
movementCounter += Time.deltaTime * 3f;
weaponParent.localPosition = Vector3.Lerp(weaponParent.localPosition, targetWeaponBobPosition, Time.deltaTime * 6f);
}
else
{
HeadBob(movementCounter, 0.15f, 0.075f);
movementCounter += Time.deltaTime * 7f;
weaponParent.localPosition = Vector3.Lerp(weaponParent.localPosition, targetWeaponBobPosition, Time.deltaTime * 10f);
}
// UI Refreshes
RefreshHealthBar();
Weapon.RefreshAmmo(ui_ammo);
}
void FixedUpdate()
{
if (!photonView.IsMine)
{
return;
}
//Axis
float t_hmove = Input.GetAxisRaw("Horizontal");
float t_vmove = Input.GetAxisRaw("Vertical");
//Controls
bool sprint = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
bool jump = Input.GetKeyDown(KeyCode.Space);
//States
bool isGrounded = Physics.Raycast(groundDetector.position, Vector3.down, 1f, ground);
bool isJumping = jump && isGrounded;
bool isSprinting = sprint && t_vmove > 0 && !jump;
//Movement
Vector3 t_direction = new Vector3(t_hmove, 0, t_vmove);
t_direction.Normalize();
float t_adjustedSpeed = speed;
if (isSprinting) t_adjustedSpeed *= sprintModifier;
Vector3 t_targetVelocity = transform.TransformDirection(t_direction) * t_adjustedSpeed * Time.deltaTime;
t_targetVelocity.y = rig.velocity.y;
rig.velocity = t_targetVelocity;
//Field of View
if (isSprinting)
{
playerCamera.fieldOfView = Mathf.Lerp(playerCamera.fieldOfView, baseFOV * sprintFOVModifier, Time.deltaTime * 8);
}
else
{
playerCamera.fieldOfView = Mathf.Lerp(playerCamera.fieldOfView, baseFOV, Time.deltaTime * 8);
}
}
#endregion
#region Private Methods
void RefreshHealthBar()
{
float t_health_ratio = (float)currentHealth / (float)maxHealth;
ui_healthbar.localScale = Vector3.Lerp(ui_healthbar.localScale, new Vector3(t_health_ratio, 1, 1), Time.deltaTime * 8f);
}
void HeadBob(float p_z, float p_x_intensity, float p_y_intensity)
{
targetWeaponBobPosition = weaponParent.localPosition = weaponParentOrgin + new Vector3(Mathf.Cos(p_z) * p_x_intensity, Mathf.Sin(p_z * 2) * p_y_intensity, 0);
}
#endregion
#region Public Methods
public void TakeDamage (int p_damage)
{
if (photonView.IsMine)
{
currentHealth -= p_damage;
RefreshHealthBar();
Debug.Log(currentHealth);
if(currentHealth <= 0)
{
manager.Spawn();
PhotonNetwork.Destroy(gameObject);
}
}
}
#endregion
}
}