New to Unity and c#. Motivated and full of extra good karma to toss out to anyone who can help! ![]()
So I built some double doors that slide open and closed when triggering a box collider using this tutorial. I have a Doors script attached to a DoorParent game object.
I also have six collectible Pick Ups (rotating cubes) that my Player can pick up. I have a PlayerMovement script attached to my Player that contains code which counts the number of picks ups collected.
I want to learn how to trigger events when a certain number of collectibles are picked up by the Player. So I am trying to create code that says if 3 Pick Ups are collected by Player, the doors slide open. Here’s the code I’ve got and I’m not sure where I’m going wrong. Right now the console is telling me: Assets/Scripts/PlayerMovement.cs(42,25): error CS1955: The member `PlayerMovement.DoorControl’ cannot be used as method or delegate
Doors
using UnityEngine;
using System.Collections;
public class Doors : MonoBehaviour {
Animator animator;
bool doorOpen;
void Start()
{
doorOpen = false;
animator = GetComponent<Animator>();
}
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "Player")
{
doorOpen = true;
DoorControl ("Open");
}
}
void OnTriggerExit(Collider col)
{
if (doorOpen)
{
doorOpen = false;
DoorControl ("Close");
}
}
void DoorControl(string direction)
{
animator.SetTrigger(direction);
}
}
PlayerMovement
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float speed;
public GameObject DoorParent;
private int count;
Animator animator;
bool doorOpen;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
doorOpen = false;
animator = DoorParent.GetComponent<Animator>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
}
if (count == 3)
{
doorOpen = true;
DoorControl ("Open");
}
}
}