Faced an issue with adding action.play
Dear developers could you please help me to solve this issue?
I want my 3d object to be clickable so that when I click the object it will jump. But unfortunately, I see this error. However, when I looked at examples of other projects where this click function is implemented, I don't see any differences between those projects and my code.
here below I attached my code(Squirrel.js):
import React, { useRef, useState, useEffect } from 'react'
import { useGLTF} from '@react-three/drei/useGLTF';
import {useAnimations} from "@react-three/drei/useAnimations";
export default function Model(props) {
const [UpDown, setUpDown] = useState(false);
const group = useRef()
const { nodes, materials, animations } = useGLTF('/squirrel.glb')
const { actions } = useAnimations(animations, group);
console.log(actions);
useEffect(() => {
if (UpDown) {
actions.UpDown.stop();
} else {
actions.UpDown.play();
}
});
return (
<group ref={group} {...props} dispose={null}>
<mesh
onClick={() => setUpDown(!UpDown)}
geometry={nodes.Plane155.geometry}
material={materials['Material.010']}
position={[-10,32,25]}
name = "Squirrel"
/>
</group>
)
}
useGLTF.preload('/squirrel.glb')