C# 与“碰撞”时减慢玩家速度;污垢“;在地面

C# 与“碰撞”时减慢玩家速度;污垢“;在地面,c#,unity3d,game-development,C#,Unity3d,Game Development,好的,所以,目前在我的游戏中,我有5或6个“警察立方体”追逐玩家,并扣除生命值,直到玩家最终死亡。我的球员还必须拿起收藏品才能到达终点线。我的球员是一个滚动的球,球有一条主要的行进路线。这条路周围有一个肮脏的环境,我需要一种方法,一旦滚动球接触到它,速度就会降低。如果有人能帮我,我将不胜感激,谢谢 using UnityEngine; using UnityEngine.UI; using System.Collections; public class _PlayerController :

好的,所以,目前在我的游戏中,我有5或6个“警察立方体”追逐玩家,并扣除生命值,直到玩家最终死亡。我的球员还必须拿起收藏品才能到达终点线。我的球员是一个滚动的球,球有一条主要的行进路线。这条路周围有一个肮脏的环境,我需要一种方法,一旦滚动球接触到它,速度就会降低。如果有人能帮我,我将不胜感激,谢谢

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class _PlayerController : MonoBehaviour {

public float speed = 75.0f;
public Text countText;
public Text winText;

private Rigidbody rb;
private int count;


void Start ()
{
    rb = GetComponent<Rigidbody>();
    count = 0;
    SetCountText ();
}

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;
        SetCountText ();
    }
}


void SetCountText ()
{
    countText.text = "Count: " + count.ToString ();
    if (count >= 25) {  
        Application.LoadLevel (2); 

        }
    }
}
使用UnityEngine;
使用UnityEngine.UI;
使用系统集合;
公共类游戏控制器:单行为{
公共浮子速度=75.0f;
公共文本;
公共文本;
私人刚体;
私人整数计数;
无效开始()
{
rb=GetComponent();
计数=0;
SetCountText();
}
无效固定更新()
{
float moveHorizontal=Input.GetAxis(“水平”);
float moveVertical=Input.GetAxis(“垂直”);
Vector3移动=新Vector3(水平移动,0.0f,垂直移动);
rb.AddForce(移动*速度);
}
无效对撞机(对撞机其他)
{
if(other.gameObject.CompareTag(“拾取”)){
other.gameObject.SetActive(false);
计数=计数+1;
SetCountText();
}
}
void SetCountText()
{
countText.text=“Count:+Count.ToString();
如果(计数>=25){
应用程序加载级别(2);
}
}
}
您可以在污垢上施加一个摩擦力,并给它一个动态摩擦力值。你给它的值将取决于你想要多少污垢减慢球员,尝试0.5作为起点

要创建物理材质,请从菜单栏中选择资源>创建>物理材质。然后将Physic材质从项目视图拖动到场景中的碰撞器上。(从链接页面粘贴副本)