I'm having a problem and i don't know how to resolve it. The error is on the line 42 of the code:
- using UnityEngine;
- using System.Collections;
-
- public class Bullet : MonoBehaviour
- {
- [Header("BulletConfig")]
- public int range;
- public int damage;
- public float mass;
- public float speed;
- [Header("Imports")]
- public PlayerController Player;
- public ParticleSystem impact;
-
-
- private Rigidbody rb;
- private Vector3 origin;
-
- void Start()
- {
- rb = GetComponents();
- origin = transform.position;
- }
-
- void Update()
- {
-
- rb.mass = mass;
-
-
- Vector3 horizontal = transform.right * 0;
- Vector3 vertical = transform.forward * 1;
- Vector3 velocity = (horizontal + vertical).normalized * speed;
- rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
-
-
- if (Vector3.Distance(origin, transform.position) > range)
- {
- Destroy(GameObject);
- }
-
- private void OnCollisionEnter(Collision collision)
- {
- Destroy(gameObject);
- if (collision.gameObject.tag == "Terrain")
- {
- GameObject eff = Instantiate(impact, collision.transform.position, Quaternion.Identity).gameObject;
- eff.transform.position += new Vector3(0, 0.1f, 0);
- eff.transform.eulerAngles = new Vector3(-90, 0, 0);
- }
- }
- }
- }