Victor S. Muniz

Victor S. Muniz

  • 1.9k
  • 2
  • 174

The modifier ‘private’ is not valid for this item

May 27 2020 6:31 PM
I'm having a problem and i don't know how to resolve it. The error is on the line 42 of the code:
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class Bullet : MonoBehaviour  
  5. {  
  6.     [Header("BulletConfig")]  
  7.     public int range;  
  8.     public int damage;  
  9.     public float mass;  
  10.     public float speed;  
  11.     [Header("Imports")]  
  12.     public PlayerController Player;  
  13.     public ParticleSystem impact;  
  14.   
  15.     //Privates  
  16.     private Rigidbody rb;  
  17.     private Vector3 origin;  
  18.   
  19.     void Start()  
  20.     {  
  21.         rb = GetComponents();  
  22.         origin = transform.position;  
  23.     }  
  24.   
  25.     void Update()  
  26.     {  
  27.         //Massa  
  28.         rb.mass = mass;  
  29.   
  30.         //Frente  
  31.         Vector3 horizontal = transform.right * 0;  
  32.         Vector3 vertical = transform.forward * 1;  
  33.         Vector3 velocity = (horizontal + vertical).normalized * speed;  
  34.         rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);  
  35.   
  36.         //Range  
  37.         if (Vector3.Distance(origin, transform.position) > range)  
  38.         {  
  39.             Destroy(GameObject);  
  40.         }  
  41.   
  42.         private void OnCollisionEnter(Collision collision)  
  43.         {  
  44.             Destroy(gameObject);  
  45.             if (collision.gameObject.tag == "Terrain")  
  46.             {  
  47.                 GameObject eff = Instantiate(impact, collision.transform.position, Quaternion.Identity).gameObject;  
  48.                 eff.transform.position += new Vector3(0, 0.1f, 0);  
  49.                 eff.transform.eulerAngles = new Vector3(-90, 0, 0);  
  50.             }  
  51.         }  
  52.     }  
  53. }  
 

Brought to you by:

Answers (2)