-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSwiftToUnity.swift
More file actions
38 lines (33 loc) · 1.35 KB
/
SwiftToUnity.swift
File metadata and controls
38 lines (33 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Foundation
@objc public class SwiftToUnity: NSObject {
@objc public static let shared = SwiftToUnity()
/// Sends a "Hello World" message to the "Canvas" GameObject by calling the "OnMessageReceived" script method on that object with the "Hello World!" message.
@objc public func swiftSendHelloWorldMessage() {
// The UnitySendMessage function has three parameters: the name of the target GameObject, the script method to call on that object and the message string to pass to the called method.
UnitySendMessage("Canvas", "OnMessageReceived", "Hello World!");
}
/// Returns the "Hello, Swift!" string.
///
/// - Returns: The "Hello, Swift!" string.
@objc public func swiftHelloWorld() -> String {
return "Hello, Swift!"
}
/// Adds two integers and returns the result.
///
/// - Parameters:
/// - x: The first integer.
/// - y: The second integer.
/// - Returns: The sum of the two integers.
@objc public func swiftAdd(_ x: Int, _ y: Int) -> Int {
return x + y
}
/// Concatenates two strings and returns the result.
///
/// - Parameters:
/// - x: The first string.
/// - y: The second string.
/// - Returns: The concatenated string.
@objc public func swiftConcatenate(_ x: String, y: String) -> String {
return x + y
}
}