从GameObject Enemy中的另一个脚本激活具有摄像机参数的功能的单位问题

问题描述 投票:0回答:1

我有一个脚本,可以通过按一下按钮使相机晃动,因为这是一个公共访问功能,如果我在放置按钮时这样做,效果很好,但是我无法实现的是调用该功能,以便每次玩家与敌人发生碰撞时,他都会发抖。我希望你能帮助我。

相机中的抖动代码为:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScreenShaker : MonoBehaviour {

    private float shakeAmount = 0.5f;

    private float shakeTime = 0.0f;
    private Vector3 initialPosition;
    private bool isScreenShaking = false;

    void Update () {
        if(shakeTime > 0)
        {
            this.transform.position = Random.insideUnitSphere * shakeAmount + initialPosition;
            shakeTime -= Time.deltaTime;
        }
        else if(isScreenShaking)
        {
            isScreenShaking = false;
            shakeTime = 0.0f;
            this.transform.position = initialPosition;
        }
    }

    public void ScreenShakeForTime(float time)
    {
        initialPosition = this.transform.position;
        shakeTime = time;
        isScreenShaking = true;
    }
}

敌人代码是:

   using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class ControladorEnemigoCirculoMediano : MonoBehaviour
    {
        void OnTriggerEnter2D(Collider2D other)
        {
            if (other.tag == "Player") 
            {
            Here I don't know what to call the public void function ScreenShakeForTime (float time); 
            I already tried many things online but when my character comes into contact with the character, I don't do the shake in the camera.
            }
        }
    }
function call unityscript
1个回答
0
投票

您能告诉我在敌方游戏对象对撞机isTrigger是否启用如果未启用,则使用OnColliderEnter2D(Collision2D other){}进行碰撞检测

© www.soinside.com 2019 - 2024. All rights reserved.