Assets\script\Weapon.cs(75,27): error CS1061: 'Camera' does not contain a definition for 'ViewportPointToRay' and no accessible extension method 'ViewportPointToRay' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?)
Вот код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Weapon : MonoBehaviour
{
public Transform FirePoint;
public GameObject PulaPrefab;
public Camera cam;
//Time Shoot
[Header("Sensitivity Time Shoot")]
public float TimeShoot = 0;
float TimeStartShoot;
//Recherge
[Header("Sensitivity recherge")]
public float ShopVolume = 7;
public float StartShopVolume = 7;
public float ShopGun = 3;
//Time shoot recherge
[Header("Sensitivity time recherge")]
public float TimeShop = 0;
float TimeStartShop;
//TextShoot
public Text TextShoot;
void FixedUpdate()
{
Shoot();
Recharge();
TextShoot.text = ShopVolume + "/" + ShopGun;
}
void Start()
{
cam = GetComponent<Camera>();
}
//Recharge
void Recharge()
{
TimeStartShop += 0.02f;
if(Input.GetKey(KeyCode.R) && TimeStartShop >= TimeShop)
{
TimeStartShop = 0;
ShopVolume = StartShopVolume;
ShopGun -= 1;
}
if (ShopGun <= 0)
{
TimeStartShop = 0;
}
}
//Shoot
void Shoot()
{
TimeStartShoot += 0.02f;
if(Input.GetKey(KeyCode.Mouse0) && TimeStartShoot >= TimeShoot)
{
Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
RaycastHit hit;
Vector3 TP;
if(Physics.Raycast(ray, out hit))
{
TP = hit.point;
}
else
{
TP = ray.GetPoint(75);
}
Vector3 DRWS = TP - FirePoint.position;
Instantiate(PulaPrefab, FirePoint.position, FirePoint.rotation);
TimeStartShoot = 0;
ShopVolume -= 1;
}
if(ShopVolume <= 0)
{
TimeStartShoot = 0;
}
}
}
Помогите пожалуйста.
Версия Unity: 2022.2.12f1.
Camera
? Если есть, переименуйте.