An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Assets\Scripts\PlayerMove.cs(33,13): error CS0120: An object reference is required for the non-static field, method, or property 'GameObject.GetComponent<AgregarScore>()'
mc santa
1
Reputation point
Hola tengo este error al ejecutar en unity y tengo estos 2 scrips
Este es el primer escrip que es sobre AgregarScore
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AgregarScore : MonoBehaviour
{
public int Puntaje = 0;
// Start is called before the first frame update
private void OnTriggerEnter (Collider other)
{
GameControler.Score += Puntaje;
}
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
y este es el segundo sccrip que es donde tengo el problema
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerMove : MonoBehaviour
{
public int vida = 10;
public Transform Dano;
public Rigidbody rb;
public GameObject meteorito;
public float TiempoMeteorito;
private float NuevoMeteorito;
public GameObject IniBala;
public GameObject balaPrefab;
public float Velbala;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(vida == 0)
{
over();
vida = 10;
GetComponent<AgregarScore>().Puntaje = 0; //en esta linea es de donde proviene el error
}
if(Input.GetKey ("1"))
{
main();
}
if(NuevoMeteorito <= 0){
NuevoMeteorito = TiempoMeteorito;
int Meteoritopost = Random.Range(-7,8);
GameObject meteoritoTemp = Instantiate(meteorito,new Vector3(Meteoritopost,10,0),Quaternion.identity);
Destroy (meteoritoTemp, 5);
}
NuevoMeteorito -= Time.deltaTime;
if (Input.GetKey("d"))
{
rb.velocity = transform.right * 12;
}
if (Input.GetKey("a"))
{
rb.velocity = -transform.right * 12;
}
if (Input.GetKey("m"))
{
GameObject TempBala = Instantiate(balaPrefab, IniBala.transform.position, IniBala.transform.rotation);
Rigidbody Temporb = TempBala.GetComponent<Rigidbody>();
Temporb.AddForce(transform.up * Velbala);
Destroy(TempBala, 4.0f);
}
}
public void main()
{
SceneManager.LoadScene("menu");
}
public void over()
{
SceneManager.LoadScene("GameOver");
}
public void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Undefined")
{
Instantiate(Dano, transform.position, transform.rotation);
}
}
public void movida(int modi)
{
vida += modi;
}
public int get_vida()
{
return vida;
}
}
les agradeceria mucho que me ayuden
Developer technologies | C#
Developer technologies | C#
Sign in to answer