New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-unity-webgl

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-unity-webgl

A Unity WebGL component for your React application

  • 5.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
increased by1.91%
Maintainers
1
Weekly downloads
 
Created
Source

react-unity-webgl

A Unity WebGL component for your React application.

installation

Install using npm. Make sure you download the version matching with your Unity version. I try to update this plugin in case of need as fast as possible.

# example
$ npm install --save react-unity-webgl@5.6.0

usage

To get stated import the Unity component from 'react-unity-webgl'. Once imported you can use the Unity component to load in your Unity content. Place the Unity tag along with a src to the json file Unity exported.

import React, { Component } from 'react';
import { Unity } from '/Projects/react-unity-webgl';

export class App extends Component {
    render() {
        return (<div className="app">
            <Unity src="Build/viewer.json" />
        </div>)
    }
}

communication

Unity allows you to send Javascript messages to the Unity content. In order to do so using React you have to import the Message function from 'react-unity-webgl'. The first parameter is the target game object name, the next is the method name, and the last is a optional parameter value.

import React, { Component } from 'react';
import { Message } from '/Projects/react-unity-webgl'

export class Menu extends Component {
    onClick () {
        Message ("myGameObjectName", "myMethodName", "paramterValue");
    }
    render() {
        return (<div className="menu">
            <div onClick={this.onClick.bind(this)}>
                Click me
            </div>
        </div>)
    }
}

styling

The player will be injected in the a component with the className "unity-container". To style to player use the following sass styling. To style the loader you can style the component with the className "unity-loader". See the example below.

/* Example styling */
.unity-container {
    canvas {
        /* ... */
    }
}
.unity-loader {
    /* ... */
    .bar {
        /* ... */
        .fill {
            /* ... */
        }
    }
}

Keywords

FAQs

Package last updated on 21 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc