获取玩家到其他玩家的门钥匙

时间:2019-06-21 13:46:30

标签: c# unity3d gameobject

制造赛车 该地图只有一张随机在地图上移动的卡 玩家必须获得卡才能越过门并获胜 抓到持卡人后,其他玩家可以从玩家那里获得这张卡 我尝试了许多编程脚本,以便该片段可以在播放器之间移动,但没有用 我该如何使震惊我的玩家随身携带这张卡? 有没有实现此目标的特定代码或算法?

These are some of the ways you tried but failed

公共布尔isHere = false;     public Transform objToFollow;

public GameObject CoinInCar; 


public float lookSpeed = 10.0f;
public float folloSpeed = 10.0f;
public Vector3 offSet;




private void FixedUpdate() {


    if (isHere){

        LookAt();
        Follow();
        CoinInCar.SetActive(true);

    } else 
    {
        CoinInCar.SetActive(false);
    }

}


void OnCollisionEnter(Collision CoinLocation){


        if (CoinLocation.gameObject.name == "Audi"){

            isHere = true ;

        } else {

            isHere = false ;
        }


    }


    void LookAt()
{
    Vector3 _lookDir = objToFollow.position - transform.position;
    Quaternion rot = Quaternion.LookRotation(_lookDir, Vector3.up);
    transform.rotation = Quaternion.Lerp(transform.rotation, rot, lookSpeed * Time.deltaTime);
}

void Follow()
{
    Vector3 _targetPos = objToFollow.position + 
                        ( objToFollow.forward * offSet.z + objToFollow.right * offSet.x + objToFollow.up * offSet.y );

        transform.position = Vector3.Lerp(transform.position, _targetPos, folloSpeed * Time.deltaTime);
}

0 个答案:

没有答案