LoginSignup
0
0

The given key was not present in the dictionary. エラー対処法教えてください。

Last updated at Posted at 2023-08-07

udonsharp sdk3でこちらのスクリプトだと 
[UdonSharp] Assets/Brick Project Studio/Apartment Kit/Scenes/Scene_02_UdonProgramSources/monbot.cs(70,75): Udon runtime exception detected!
An exception occurred during EXTERN to 'UnityEngineComponent.__GetComponent__T'.
Parameter Addresses: 0x0000002C, 0x00000019, 0x0000002B

The given key was not present in the dictionary.

このエラーがでてきてOnPickupUseDown()してもスクリプトが実行されません。
対処法どなたか教えていただきたいです。
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class monbot : UdonSharpBehaviour
{
public float growTime = 0.5f;
public float shrinkTime = 0.1f;
public float shrinkDelay = 1.0f;
public Vector3 grownScale = new Vector3(2, 2, 2);
public AudioClip soundClip1;
public AudioClip soundClip2;
public Transform targetPosition; // テレポートする場所
public GameObject triggerObject; // トリガーとなるオブジェクト

private Vector3 originalScale;
private float timer = 0.0f;
private bool isGrowing = false;
private bool isShrinking = false;
private bool isWaitingToShrink = false;
private AudioSource audioSource;

void Start()
{
    originalScale = transform.localScale;
    audioSource = GetComponent<AudioSource>();
}

void Update()
{
    if (isGrowing)
    {
        timer += Time.deltaTime;
        transform.localScale = Vector3.Lerp(originalScale, grownScale, timer / growTime);
        if (timer >= growTime)
        {
            isGrowing = false;
            timer = 0.0f;
        }
    }
    else if (isWaitingToShrink)
    {
        timer += Time.deltaTime;
        if (timer >= shrinkDelay)
        {
            isWaitingToShrink = false;
            isShrinking = true;
            timer = 0.0f;
        }
    }
    else if (isShrinking)
    {
        timer += Time.deltaTime;
        transform.localScale = Vector3.Lerp(grownScale, originalScale, timer / shrinkTime);
        if (timer >= shrinkTime)
        {
            isShrinking = false;
            timer = 0.0f;
        }
    }
}

public override void OnPickupUseDown()
{
    // プレイヤーがトリガーの中にいるかどうかを判定する
    Collider[] colliders = Physics.OverlapBox(triggerObject.transform.position, triggerObject.transform.localScale / 2);
    foreach (Collider collider in colliders)
    {
        VRCPlayerApi playerApi = collider.GetComponent<VRCPlayerApi>();
        if (playerApi != null) // プレイヤーがいる場合
        {
            // プレイヤーをテレポートする
            playerApi.TeleportTo(targetPosition.position, targetPosition.rotation);
        }
    }

    // プレイヤーがトリガーの中にいない場合は、元の処理を実行する
    if (transform.localScale == originalScale)
    {
        isGrowing = true;
        isWaitingToShrink = false;
        isShrinking = false;
        timer = 0.0f;

        // Play the first sound
        audioSource.PlayOneShot(soundClip1);
    }
    else
    {
        isGrowing = false;
        isWaitingToShrink = true;
        isShrinking = false;
        timer = 0.0f;

        // Play the second sound
        audioSource.PlayOneShot(soundClip2);
    }
}

}

VRCPlayerApi playerApi = collider.GetComponent();
if (playerApi != null) // プレイヤーがいる場合
{
// プレイヤーをテレポートする
playerApi.TeleportTo(targetPosition.position, targetPosition.rotation);
}
この部分がエラーを起こしているみたいです

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0