Why doesn't this collision code work?

I’ve been following a tutorial book and I’ve got this book :

using UnityEngine;
using System.Collections;

public class PowerCell : MonoBehaviour {
	public static int charge = 0;
	public AudioClip collectSound;
	// Use this for initialization
	void Start () {
		charge = 0;
	}
	
	void CellPickup(){
		AudioSource.PlayClipAtPoint(collectSound, transform.position);
		charge++;
	}
	
	public float rotationSpeed = 100.0f;
	
	
	// Update is called once per frame
	void Update () {
		transform.Rotate(new Vector3(0,rotationSpeed * Time.deltaTime,0));
		

	}
	
	void OnTriggerEnter(Collider col){
		if(col.gameObject.tag == "Playerrr") {
			col.gameObject.SendMessage("CellPickup");
			Destroy(gameObject);
		}
	}

}

Try this. And let me know if it worked. I’ve only been scripting for a week but I have something similar.


public void OnTriggerEnter(Collider col){
   if(col.gameObject.tag == "Playerrr") 
   col.gameObject.SendMessage("CellPickup")
   Destroy(gameObject);

I think you just need to make it public if your accessing an object that the script isn’t attached to and get rid of the semicolons and the 2 brackets starting after the if function and at the end of the function.

It looks good, maybe your tag is not “Playerrr”

I think that you have to send message to powercell self, not player. so try this:
void OnTriggerEnter(Collider col){
if(col.gameObject.tag == “Playerrr”) {
gameObject.SendMessage(“CellPickup”);
Destroy(gameObject);
}
}