using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed;
public GameObject item;
public Transform shit;
private Rigidbody rb;
private int vertical, horizontal;
private int count = 0;
void Start ()
{
rb = GetComponent ();
vertical = 1;
horizontal = 0;
//item.SetActive (false);
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.CompareTag (“Pick Up”))
{
other.gameObject.SetActive (false);
count = count + 1;
//SetCountText ();
}
}
void Update ()
{
/*
float moveHorizontal = Input.GetAxis (“Horizontal”);
float moveVertical = Input.GetAxis (“Vertical”);
if ((transform.position.x >= 10f && moveHorizontal > 0) || (transform.position.x <= -10f && moveHorizontal < 0))
{
moveHorizontal = 0;
}
if ((transform.position.z >= 10f && moveVertical > 0) || (transform.position.z <= -10f && moveVertical < 0))
{
moveVertical = 0;
}
Vector3 movement = new Vector3 (moveHorizontal * Time.deltaTime, 0.0f, moveVertical * Time.deltaTime);
print (moveHorizontal + “and” + moveVertical + “position” + transform.position);
//rb.MovePosition (transform.position + movement * speed);
transform.Translate (movement * speed);
//transform.Rotate (0, moveHorizontal, 0);
*/
if (Input.GetKeyDown (“up”))
{
vertical = 1;
horizontal = 0;
}
if (Input.GetKeyDown (“down”))
{
vertical = -1;
horizontal = 0;
}
if (Input.GetKeyDown (“left”))
{
vertical = 0;
horizontal = 1;
}
if (Input.GetKeyDown (“right”))
{
vertical = 0;
horizontal = -1;
}
if ((transform.position.z >= 10f && horizontal == 1) || (transform.position.z <= -10f && horizontal == -1))
{
horizontal = 0;
}
if ((transform.position.x >= 10f && vertical == 1) || (transform.position.x <= -10f && vertical == -1))
{
vertical = 0;
}
print (vertical + " and " + horizontal + " and " + transform.position.x);
Vector3 movement = new Vector3 (vertical * Time.deltaTime, 0.0f, horizontal * Time.deltaTime);
rb.MovePosition (transform.position + movement * speed);
if (count>0)
{
if (Input.GetKeyDown (“space”))
{
Instantiate (item, shit.position, shit.rotation);
count = count - 1;
}
}
}
}
Here’s the whole coding for the player. My game basically tells about a worm that eat up food and for each food it consumes, it will be able to gain one charge to spit out faeces on its location. But i do not want the faeces to stick to my main character which is the blue cube. The capsule represents the faeces.